• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 9 pages
Exam (elaborations)

Chapter 5 Data Structures Exam Questions with Answers

Document preview thumbnail
Preview 2 out of 9 pages

Chapter 5 Data Structures Exam Questions with Answers linked list - Correct Answers: A sequence of items arranged one after another, with each item connected to the next by a link is called a(n) head pointer - Correct Answers: A pointer to the first node in a linked list is called the tail pointer - Correct Answers: A pointer to the last node in a linked list is called the an empty list - Correct Answers: A linked list that contains no nodes is called what? null pointer - Correct Answers: A special C++ constant used for any pointer value that has no place to point is called a nodes - Correct Answers: A collection of _______ makes up a linked list. (*p).m - Correct Answers: If p is a pointer to a class, and m is a member of the class, then p-m means the same as A. (*p).m B. *p.m C. (p.)m D. (*p.)m E. p.m node - Correct Answers: What is the data type of *head_ptr in Figure 5.3 on page 224? A. node B. pointer to a node C. value_type D. data_field pointer to node - Correct Answers: What is the data type of head_ptr in Figure 5.3 on page 224? A. pointer to a node B. node C. value_type D. data_field - Correct Answers: What is the data type of head_ptr-data( ) in Figure 5.3 on page 224? (The definition of data( ) is on page 226.) A. data_field B. pointer to a node C. node D. value_type - Correct Answers: What will the following function return? int calculate(const node* head_ptr) { const node *ptr; int n = 0; for (ptr = head_ptr-get_next(), ptr != NULL; ptr = ptr-get_next()) n++; return n; } A. the length of the list plus 1 B. the length of the list plus 2 C. the length of the list minus 2 D. the length of the list E. the length of the list minus 1 the beginning of the linked list - Correct Answers: The two lines of code below will insert a new node into a linked list at which location? node *ptr = new node(x, head_ptr); head_ptr = ptr; A. after the node pointed to by head_ptr B. the end of the linked list C. the beginning of the linked list D. after the node pointed to by ptr - Correct Answers: The two lines of code below will insert a new node into a linked list at which location? node *ptr = new node(x, previous_ptr-get_next()); previous_ptr-set_next(ptr); A. before the node pointed to by previous_ptr B. after the node pointed to by previous_ptr C. after the node pointed to by ptr D. after the node pointed to by previous_ptr-get_next() E. the end of the linked list a pointer to the node containing the value of x or the NULL pointer - Correct Answers: What does the following function return? node* list_search(node *head_ptr, double x) { node *ptr; for (ptr = head_ptr; ptr != NULL; ptr = ptr-get_next()) if (x == ptr-get_value()) return ptr; return NULL; } A. the value of x B. TRUE or FALSE C. the position in the linked list of the node containing the value of x D. a pointer to the node containing the value of x or the NULL pointer deletes the first node in the linked list - Correct Answers: What action does the following code segment perform? node *ptr = head_ptr; head_ptr = head_ptr-get_next(); delete ptr; A. deletes the node pointed to by head_ptr-get_next( ) B. deletes the first node in the linked list C. deletes the node that comes immediately after the node pointed to by head_ptr D. deletes the last node in the linked list deletes the node that comes after the node initially pointed to by previous_ptr - Correct Answers: What action does the following code segment perform? node *ptr = previous_ptr-get_next(); previous_ptr-set_next(ptr-get_next()); delete ptr; A. deletes the node initially pointed to by previous_ptr B. deletes the node that comes before the node initially pointed to by previous_ptr C. deletes the node that comes after the node initially pointed to by previous_ptr 12 - Correct Answers: For the linked list shown below, what will the code segment display? Head_ptr - 4 - 6 - 12, NULL node *ptr = head_ptr-get_next( ); ptr = ptr-get_next( ); cout ptr-get_value( ); A. 6 B. 4 C. nothing D. 12 10 - Correct Answers: For the linked list shown below, what will the code segment display? Head_ptr - 4 - 6 - 12 - 20, NULL node *ptr; int sum = 0; for (ptr = head_ptr; ptr-get_value( ) 10; ptr = ptr-get_next( )) sum += ptr-get_value( ); cout sum endl; A. 42 B. 6 C. 10 D. 4 E. 22 32 - Correct Answers: For the linked list shown below, what will the code segment display? Head_ptr - 4 - 6 - 12 - 20,NULL node *ptr1, *ptr2; ptr1 = head_ptr; ptr2 = ptr1; ptr2 = ptr2-get_next( ); ptr2 = ptr2-get_next( ); ptr1 = ptr2-get_next( ); cout ptr1-get_value( ) + ptr2-get_value( ) endl; A. 10 B. 32 C. 24 D. 18 E. 26 - Correct Answers: For the linked list shown below, what will the code segment display? Head_ptr - 4 - 6 - 12,NULL node *ptr; for (ptr = head_ptr-get_next( ); ptr != NULL; ptr = ptr-get_next( )) cout ptr-get_data( ); A. 46 B. 46120 C. 612 D. 4612 E. nothing

Content preview

Chapter 5 Data Structures
Exam Questions with Answers
linked list - Correct Answers: A sequence of items arranged one after another, with each item connected
to the next by a link is called a(n)



head pointer - Correct Answers: A pointer to the first node in a linked list is called the



tail pointer - Correct Answers: A pointer to the last node in a linked list is called the



an empty list - Correct Answers: A linked list that contains no nodes is called what?



null pointer - Correct Answers: A special C++ constant used for any pointer value that has no place to
point is called a



nodes - Correct Answers: A collection of _______ makes up a linked list.



(*p).m - Correct Answers: If p is a pointer to a class, and m is a member of the class, then p->m means
the same as



A. (*p).m

B. *p.m

C. (p.)m

D. (*p.)m

E. p.m



node - Correct Answers: What is the data type of *head_ptr in Figure 5.3 on page 224?



A. node

, B. pointer to a node

C. value_type

D. data_field



pointer to node - Correct Answers: What is the data type of head_ptr in Figure 5.3 on page 224?



A. pointer to a node

B. node

C. value_type

D. data_field



- Correct Answers: What is the data type of head_ptr->data( ) in Figure 5.3 on page 224? (The definition
of data( ) is on page 226.)



A. data_field

B. pointer to a node

C. node

D. value_type



- Correct Answers: What will the following function return?



int calculate(const node* head_ptr)



{



const node *ptr;



int n = 0;

Document information

Uploaded on
April 12, 2025
Number of pages
9
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$17.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
2
Followers
2
Items
1670
Last sold
1 year ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions