



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Main points of this exam paper are: Member Function, Cout Statements, Private Members, Empty List, Newitem, Doublenode, Member Function
Typology: Exams
1 / 6
This page cannot be seen from the preview
Don't miss anything!
class DoubleList{ // public function declarations here ... private: struct DoubleNode{ ListItemType item; // data in the node DoubleNode* next; // points to next node DoubleNode* precede; // points to previous node }; DoubleNode* head; // points to first node };
(a) Write a member function void DoubleList::removeFirstNode() which deletes the first node from a doubly linked list. (b) Assume the DoubleNode* variable curr points to a node in our dou- bly linked list. Write a few lines of code to remove this node curr from the list. (Be careful: what should happen if curr is at the beginning or end of the list?) (c) Write a member function DoubleList::DoubleNode DoubleList::find(int index) which returns a pointer to the node at position index in the doubly linked list. Your function should return NULL if the index is out of range (note our class DoubleList does not have a size data member: how can you determine if index is out of range in this case?)
#include
#include
(a) Create an empty list. (b) Destroy a list. (c) Determine whether a list is empty. (d) Determine the number of items in a list. (e) Insert an item at a given position in the list. (f) Delete the item at a given position in the list. (g) Look at (retrieve) the item at a given position in the list.
Using only the ADT List operations (a)-(g) above, describe how to replace an item at a given position on a list with a new item. (So, for example, given the list of integers 0,3,8,9,4,10, if the fourth item is to be replaced with a 7, the new list will be 0,3,8,7,4,10.) You may write your answer in (precise) words, in pseudocode, or in representative C++ code.
head
(b) 3