60 likes | 322 Views
0. Given the declarations struct ListNode { float volume; ListNode* link; }; ListNode* ptr; which of the following statements advances ptr to point to the next node of a list?. a. ptr = ptr->link; b. ptr++; c. *ptr = ptr->link; d. ptr = *ptr; e. ptr->link = ptr;.
E N D
0 Given the declarations struct ListNode { float volume; ListNode* link; }; ListNode* ptr; which of the following statements advances ptr to point to the next node of a list? • a. ptr = ptr->link; • b. ptr++; • c. *ptr = ptr->link; • d. ptr = *ptr; • e. ptr->link = ptr;
0 The following code, which builds a linked list with the numbers 18 and 32 as its components, has a missing statement. What should the statement be? struct NodeType { int data; NodeType* link; }; NodeType* head, p, q; p = new NodeType; head = p; p->data = 18; q = new NodeType; q->data = 32; <-- Statement is missing here q->link = NULL; • a. p = q; • b. p->link = new NodeType; • c. p->link = q; • d. p->link = q->link;
0 What is special about the last node in a dynamic linked list? • a. Its component (data) member is undefined. • b. Its component (data) member contains the value 0. • c. Its link member is undefined. • d. Its link member contains the value NULL. • e. It has no link member
0 If a program accidentally corrupts the link member of a node in the middle of a linked list, how much of the original linked list is now inaccessible? a. only the corrupted node is inaccessible b. all nodes preceding the corrupted node are inaccessible c. all nodes following the corrupted node are inaccessible d. the entire linked list is inaccessible
0 Given the declarations struct ListNode { float volume; ListNode* link; }; ListNode* headPtr; assume that headPtr is the external pointer to a linked list of many nodes. Which statement removes the first node from the list? (Ignore deallocation of the node.) • a. headPtr = headPtr->link; • b. *headPtr = headPtr->link; • c. headPtr->link = headPtr->link->link; • d. headPtr = headPtr.link; • e. none of the above
0 The following code is meant to search a linked list of 4 nodes for item. If item is not in the list, what is printed? currPtr = head ;string found = “false”;int position = 0; while ( item != currPtr->info && currPtr != NULL ) { currPtr = currPtr->link ; position++; } if (item == currPtr->info) found = “true”;cout << “found:”<<found<<“ position:”<<position<<endl; • a. found:false position: 3 • b. found:false position: 4 • c. found:true position: 3 • d. found:true position: 4 • e. none of the above