Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Code from: // Data Structures and Algorithms in C++, Goodrich, Tamassia, and Mount, 2nd Ed., 2011. // #pragma once #include using namespace std; template

image text in transcribed

// Code from: // Data Structures and Algorithms in C++, Goodrich, Tamassia, and Mount, 2nd Ed., 2011. // #pragma once #include using namespace std; template class SLinkedList; // forward declaration to be used when declaring SNode template class SNode { // singly linked list node private: E elem; // linked list element value SNode *next; // next item in the list friend class SLinkedList; // provide SLinkedList access }; template class SLinkedList { // a singly linked list public: SLinkedList(); // empty list constructor ~SLinkedList(); // destructor bool empty() const; // is list empty? E& front(); // return front element void addFront(const E& e); // add to front of list void removeFront(); // remove front item list int size() const; // list size private: SNode* head; // head of the list int n; // number of items }; template SLinkedList::SLinkedList() // constructor : head(NULL), n(0) { } template bool SLinkedList::empty() const // is list empty? { return head == NULL; // can also use return (n == 0); } template E& SLinkedList::front() // return front element { if (empty()) throw length_error("empty list"); return head->elem; } template SLinkedList::~SLinkedList() // destructor { while (!empty()) removeFront(); } template void SLinkedList::addFront(const E& e) { // add to front of list SNode* v = new SNode; // create new node v->elem = e; // store data v->next = head; // head now follows v head = v; // v is now the head n++; } template void SLinkedList::removeFront() { // remove front item if (empty()) throw length_error("empty list"); SNode* old = head; // save current head head = old->next; // skip over old head delete old; // delete the old head n--; } template int SLinkedList::size() const { // list size return n; }

template

bool SLinkedList::identicalEnds()

{

// your code goes here

}

IV. (15 points) implementing data structure operations Write C++ code for a new public member function to be added to the singly linked list data structure used in class. Write C++ code for a new public member function to be added to the singly linked list data structure. The function should return true if the front and back element are the same. You may assume that the element type E can be compared with the == operator. The function returns false if the list is empty. The function declaration should be: bool identicalEnds (); You may use loops or recursion as needed. If necessary, you may add private helper function(s). La definition of the SLinkedList class and its related SNode class are shown below along with the space to write your function

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

Step: 3

blur-text-image

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

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

Tool (SIP): Go back and rework your school improvement plan so that

Answered: 1 week ago