Question: C++ Program Create a Double linked List class using the given base code and write a program to test the class. The class should have
C++ Program
Create a Double linked List class using the given base code and write a program to test the class.
The class should have the following methods:
Create the list
Insert an item
delete an item
Return the current
Move
One node left
One node right
Move to the beginning
Move to the end
templateclass doublenode{ public: datatype data; doublenode *llink, *rlink; }; template class doublelink{ private: doublenode *headnode, *current, *temp; public: doublelink(); bool ddlist_empty(); void insertnode(datatype d); void deletenode(void); datatype returncurrent(void); void moveBegin(void); void moveEnd(void); void moveRight(void); void moveLeft(void); bool currentHead(void); void moveLoopRight(void); }; template void doublelink ::deletenode(void){ //current has been set if(current != headnode){ temp = current; temp->llink->rlink = temp->rlink; temp->rlink->llink = temp->llink; current = headnode; delete(temp); } }; template void doublelink ::insertnode(datatype d){ // current has been set to the point in the list temp =new doublenode; temp->data= d; }; template bool doublelink ::ddlist_empty(){ if(headnode == headnode->llink && headnode == headnode->rlink){ return true; }else{ return false; } } template doublelink ::doublelink(){ headnode = new doublenode; headnode->llink = headnode; headnode->rlink = headnode; };
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
