Quiz 10

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What are the contents of the QUEUE after this code from front to back? enqueue( 10 ); dequeue(); enqueue( 20 ); dequeue(); enqueue( 30 ); enqueue( 40 ); a. 30, 40 b. 10 c. 40, 30 d. 10, 20, 30, 40

a. 30, 40

What are the contents of the QUEUE after this code from front to back? enqueue( 10 ); enqueue( 20 ); enqueue( 30 ); dequeue(); enqueue( 40 ); dequeue(); dequeue(); a. 40 b. 10, 20, 30, 40 c. 10, 30, 40 d. 10, 20

a. 40

Assume you have a linked list of nodes with an integer data member. Nodes are stored in ascending order with respect to that integer data member. In what order (in terms of the integer data member in the linked list nodes) will this function print the values assuming the initial call passes in the head pointer of the linked list? void printLinkedList( LLNode* h ) { if( h == NULL ) return; printLinkedList( h->next ); printf( "%d ", h->value ); } a. Descending order b. Ascending order c. Random order d. This function results in stack overflow

a. Descending order

Assume that you are in the middle of linked list and that ptr is pointing a node. What is the correct code to remove the node AFTER ptr? a. Node *temp = ptr->next; ptr->next = ptr->next->next; free( ptr ); b. Node *temp = ptr->next; ptr->next = ptr->next; free( ptr ); c. free( ptr->next ); d. Node *temp = ptr; ptr->next = ptr->next->next; free( ptr );

a. Node *temp = ptr->next; ptr->next = ptr->next->next; free( ptr );

What does pop mean with respect to a stack? a. To remove from the top of a stack b. To add to the bottom of a stack c. To remove from the bottom of a stack d . To add to the back of a queue

a. To remove from the top of a stack

What is the term used to describe adding to a queue? a. enqueue b. add c. insert d. dequeue

a. enqueue

What do we use to define a node for a linked list in C? a. struct b. int c. enum d. string.h

a. struct

What are the contents in the STACK after the following code from top to bottom? push( 10 ); push( 20 ); pop(); pop(); push( 30 ); push( 40 ); push( 50 ); pop(); pop(); a. 10 b. 30 c. 20 d. 10, 20, 30, 40, 50, 60

b. 30

What is a dummy node? a. A temporary node used for swapping b. A node inserted at the head of the linked list with all its other data members nulled c. A NULL value d. A node pointing at NULL

b. A node inserted at the head of the linked list with all its other data members nulled

What data structure matches with this description? A data structure were values are stored in a consecutive manner and directly accessible by its positional index a .binary tree b. array c. linked list d. hash table

b. array

Given this code that builds a singly linked list where addNode() will create and add a new node with the integer value passed in to the front of the linked list and removeNode() removes from the front of the linked list, what is output of the code? 7 Node *head = NULL; 8 Node *ptrA, *ptrB, *ptrC; 9 10 head = addNode( head, 70 ); 11 ptrA = head; CS1713 12 head = addNode( head, 20 ); 13 head = addNode( head, 50 ); 14 head = addNode( head, 30 ); CS1713 15 ptrB = head->next; 16 head = removeNode( head ); 17 head = addNode( head, 10 ); CS1713 18 head = addNode( head, 40 ); 19 head = removeNode( head ); 20 ptrC = head; 21 22 printf( "%d, %d, %d\n", ptrA->value, ptrB->value, ptrC->value ); a. 40, 30, 70 b. 70, 30, 40 c. 70, 50, 10 d. 10, 70, 50 e. 20, 50, 30

c. 70, 50, 10

What is the purpose of a destructor function for a linked list? a. To create a new node b. To free the head pointer c. To free up all the memory dynamically for each linked list node d. To copy the linked list into a file output

c. To free up all the memory dynamically for each linked list node

Assume you have two pointers ptrA and ptrB pointing to two adjacent nodes in the linked list and n as a pointer to a new node. What is the correct code to insert n between ptrA and ptrB in a linked list? a. ptrA->next = n; n->next = ptrB; b. ptrA = n = ptrB; c. n->next = ptrB; ptrA->next = n; d. ptrA-next = n->next = ptrB;

c. n->next = ptrB; ptrA->next = n;

What abstract data type follows the first-in, first-out rule? a. stack b. array c. queue d .binary tree

c. queue

What abstract data type follows the last in, first out rule? a. hash table b. queue c. stack d. graph

c. stack

Which of the following struct declarations is correct for a singly linked list? a. typedef struct Node { int value; Node *next; } b. typedef struct Node { int value; struct Node *previous; struct Node *next; } Node; c. typedef struct Node { int value; struct Node *next; } Node; d. typedef struct Node* { int value; } Node*;

c. typedef struct Node { int value; struct Node *next; } Node;

What does it mean to peek a stack? a. Removes the top of the stack b. Gets the bottom of the stack c. Gets the second item of the stack d. Gets the top of the stack without removing it

d. Gets the top of the stack without removing it

Assume that h is a pointer to the head of the linked list with many nodes in it. We want to the head to be pointing at the next item in the linked list. h = h->next; If the above statement is all there is, which of the following statements is NOT true? a. You lost track of the original head node b. The head is now pointing to what used to be the second node in the linked list c. Memory leak d. The original head is deallocated

d. The original head is deallocated


Set pelajaran terkait

Anxiety & Obsessive Compulsive Disorders - CC

View Set

Disorder of Musculoskeletal Function: Developmental & Metabolic Disorders

View Set

Laboratory 20: the pattern of inheritance

View Set

Chapter 15 "What is freedom?": Reconstruction , Give Me Liberty Ch. 15,

View Set