Question: #ifndef H_circularLinkedList #define H_circularLinkedList #include #include using namespace std; template struct nodeType { Type info; nodeType *link; }; template class circularLinkedList { public: const circularLinkedList

#ifndef H_circularLinkedList #define H_circularLinkedList #include #include using namespace std;

template struct nodeType { Type info; nodeType *link; };

template class circularLinkedList { public: const circularLinkedList& operator= (const circularLinkedList&); //Overloads the assignment operator. void initializeList(); //Initializes the list to an empty state. //Postcondition: first = nullptr, last = nullptr, // count = 0 bool isEmptyList(); //Function to determine whether the list is empty. //Postcondition: Returns true if the list is empty; // otherwise, returns false.

void print() const;

int length(); //Function to return the number of nodes in the //list. //Postcondition: The value of count is returned. void destroyList(); //Function to delete all the nodes from the list. //Postcondition: first = nullptr, last = nullptr, // count = 0 Type front(); //Function to return the first element of the list. //Precondition: The list must exist and must not be //empty. //Postcondition: If the list is empty, then the // program terminates; otherwise, // the first element of the list is // returned. Type back(); //Function to return the last element of the //list. //Precondition: The list must exist and must not //be empty. //Postcondition: If the list is empty, then the // program terminates; otherwise, // the last element of the list is // returned.

bool search(const Type& searchItem); //Function to determine whether searchItem is in //the list. //Postcondition: Returns true if searchItem is found // in the list; otherwise, it returns // false.

void insertNode(const Type& newitem);

void deleteNode(const Type& deleteItem); //Function to delete deleteItem from the list. //Postcondition: If found, the node containing // deleteItem is deleted from the // list, first points to the first // node, and last points to the last // node of the updated list.

circularLinkedList(); //Default constructor //Initializes the list to an empty state. //Postcondition: first = nullptr, last = nullptr, // count = 0

circularLinkedList(const circularLinkedList& otherList); //Copy constructor

~circularLinkedList(); //Destructor //Deletes all the nodes from the list. //Postcondition: The list object is destroyed.

protected: int count; //variable to store the number of //elements in the list nodeType *first; //pointer to the first node of //the list nodeType *last; //pointer to the last node of //the list private: void copyList(const circularLinkedList& otherList); //Function to make a copy of otherList. //Postcondition: A copy of otherList is created // and assigned to this list. };

template bool circularLinkedList::isEmptyList() { // function to determine if list is empty }

template circularLinkedList::circularLinkedList() // default constructor { first = nullptr; count = 0; }

template void circularLinkedList::destroyList() { // function to destroy the list }

template void circularLinkedList::initializeList() { destroyList(); //if the list has any nodes, delete them }

template int circularLinkedList::length() { // function to find the length of the list } // end length

template Type circularLinkedList::front() { assert(first != nullptr); return first->link->info; //return the info of the first node }//end front

template Type circularLinkedList::back() { assert(first != nullptr); return first->info; //return the info of the first node }//end back

template bool circularLinkedList::search(const Type& searchItem) { // function to search the list for a given item }//end search

template void circularLinkedList::insertNode(const Type& newitem) { // function to insert an item into the list }//end insertNode

template void circularLinkedList::deleteNode(const Type& deleteItem) { // function to delete an item from the list } //end deleteNode

//Overloading the stream insertion operator template void circularLinkedList::print() const { // function to print the list }

template circularLinkedList::~circularLinkedList() // destructor { destroyList(); }//end destructor

template void circularLinkedList::copyList (const circularLinkedList& otherList) { // function to copy the list }//end copyList

//copy constructor template circularLinkedList::circularLinkedList (const circularLinkedList& otherList) { first = nullptr;

copyList(otherList); }//end copy constructor

//overload the assignment operator template const circularLinkedList& circularLinkedList::operator= (const circularLinkedList& otherList) { if (this != &otherList) //avoid self-copy { copyList(otherList); }//end else

return *this; }

#endif

(Circular linked lists) This chapter defined and identified various operations on a circular linked list.

Write the definitions of the class circularLinkedListand its member functions. (You may assume that the elements of the circular linked list are in ascending order.)

I was given a main.cpp of:

//This program tests various operation of a linked list //45 67 23 89 -999

#include #include "circularLinkedList.h" using namespace std;

void testCopyConstructor(circularLinkedList oList);

int main() { circularLinkedList list1, list2; int num;

cout << "Enter number ending with -999" << endl; cin >> num;

while (num != -999) { list1.insertNode(num); cin >> num; }

cout << endl;

cout << "List 1: "; list1.print(); cout << endl;

cout << "Length List 1: " << list1.length() << endl;

cout << "Enter the number to be searched: "; cin >> num; cout << endl;

if (list1.search(num)) cout << num << " found in the list" << endl; else cout << num << " not in the list" << endl;

cout << "Enter the number to be deleted: "; cin >> num; cout << endl;

list1.deleteNode(num);

cout << "After deleting the node, " << "List 1: "; list1.print(); cout << endl;

cout << "Length List 1: " << list1.length() << endl;

list2 = list1;

cout << "List 2: "; list2.print(); cout << endl;

cout << "Length List 2: " << list2.length() << endl;

testCopyConstructor(list1);

cout << "List 1: "; list1.print(); cout << endl;

return 0; }

void testCopyConstructor(circularLinkedList oList) { }

and i was given a circularLinkedList.h of:

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!