Form a model of sinle-linked circular list, make a description of it and develop
ID: 1947519 • Letter: F
Question
Form a model of sinle-linked circular list, make a description of it and develope list processingoperations:
a) Findith, InsertBefore, Update;
b) FindKey, InsertAfter, Terminate;
c) FindFirst, Delete (previous element becomes a new current element), PrintList;
d) FindLast, Delete (next element becomes a new current element), FindPrior.
Explanation / Answer
// Program for singly linked Circular list #include #include struct SLinkCircularList { std::string data; SLinkCircularList *next; SLinkCircularList() : data(""), next(this) { } SLinkCircularList(const char *value) : data(value), next(this) { } SLinkCircularList* InsertNext(const char *data) { SLinkCircularList *node = new SLinkCircularList(data); if(this->next == this) // only one node in the circular list { // Easy to handle, after the two lines of executions, // there will be two nodes in the circular list node->next = this; this->next = node; } else { // Insert in the middle SLinkCircularList *temp = this->next; node->next = temp; this->next = node; } return node; } bool DeleteNext() { if(this->next == this) { std::cout next; this->next = this->next->next; delete pNode; } void Traverse(SLinkCircularList *node = NULL) { if(node == NULL) node = this; std::coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.