Question: Implement the circular linked list in which the next pointer of the last node will be pointing to the first link node of the list.

Implement the circular linked list in which the next pointer of the last node will be pointing to the first link node of the list. Modify the code of Fig 4.8 to implement the cicular singly linked list. Test all member functions with your own data and given data

Given data:

LL1 : 40, 60, 80, 10, 120, 1000
LL2 : 1, 3.50, 5, 5.8, 6, 6.5

Implement the circular linked list in which the next pointer of the

last node will be pointing to the first link node of the

// Linked list implementation template class LList: public List private: Link tail; Linkcurr; int cnt; / Pointer to list headeir // Pointer to last element // Access to current element // Size of list void init) // Intialization helper method curr tail -head new Link ; void removeal1)// Return link nodes to free store while (head !=NULL) { currhead; head head->next; delete curr; public LList (int size defaultSize) init LList ) removeall ); ) void print) const; void clear removeall); init / Constructor // Destructor // Print list contents // Clear list // Insert "it" at current position void insert (const E& it) curr->nextnew Link (it, curr->next) if (tail-= curr) tail curr->next ; // New tail cnt++ void append (const E& it) i // Append "it" to list tail = cnt++ tail->next new Link (it, NULL) ; // Remove and return current element E remove) ( Assert (curr-> next != NULL, "No element"); E it curr->next->element Link* |temp curr->next ; if (tail-curr->next) tai! = curr ; // Reset tail curr->next - curr->next->next; // Remove from list delete ltemp; cnt-- return it; // Remember valiu // Remember link node // Reclaim space // Decrement the count Figure 4.8 A linked list implementation // Linked list implementation template class LList: public List private: Link tail; Linkcurr; int cnt; / Pointer to list headeir // Pointer to last element // Access to current element // Size of list void init) // Intialization helper method curr tail -head new Link ; void removeal1)// Return link nodes to free store while (head !=NULL) { currhead; head head->next; delete curr; public LList (int size defaultSize) init LList ) removeall ); ) void print) const; void clear removeall); init / Constructor // Destructor // Print list contents // Clear list // Insert "it" at current position void insert (const E& it) curr->nextnew Link (it, curr->next) if (tail-= curr) tail curr->next ; // New tail cnt++ void append (const E& it) i // Append "it" to list tail = cnt++ tail->next new Link (it, NULL) ; // Remove and return current element E remove) ( Assert (curr-> next != NULL, "No element"); E it curr->next->element Link* |temp curr->next ; if (tail-curr->next) tai! = curr ; // Reset tail curr->next - curr->next->next; // Remove from list delete ltemp; cnt-- return it; // Remember valiu // Remember link node // Reclaim space // Decrement the count Figure 4.8 A linked list implementation

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!