Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

// 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions

Question

1. Which position would you take?

Answered: 1 week ago