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
template
template
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
~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
template
template
template
template
template
template
template
template
template
template
//Overloading the stream insertion operator template
template
template
//copy constructor template
copyList(otherList); }//end copy constructor
//overload the assignment operator template
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
void testCopyConstructor(circularLinkedList
int main() { circularLinkedList
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
and i was given a circularLinkedList.h of:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
