Question: Implement linkedList class. The header file, linkedList.h is given. (with conditions) . You can create your own client program to test it. A simple client

Implement linkedList class. The header file, linkedList.h is given. (with conditions) . You can create your own client program to test it. A simple client program, #include #include "LinkedList.h" using namespace std; int main() { linkedList list; list.insertFirst(10); list.insertFirst(20); list.insertFirst(30); list.print(); list.insertLast(40); list.print(); system("pause"); return 0; } will generate the following output. List has 3 items: [30] [20] [10] List has 4 items: [30] [20] [10] [40] #ifndef H_LinkedListType #define H_LinkedListType #include using namespace std; //Definition of the node struct nodeType { int info; nodeType *link; }; //***************** class linkedList **************** class linkedList { private: nodeType* first; nodeType* last; int count; public: void initializeList(); //Initialize the list to an empty state. //Postcondition: first = nullptr, last = nullptr, // count = 0; bool isEmptyList() const; //Function to determine whether the list is empty. //Postcondition: Returns true if the list is empty, // otherwise it returns false. void print() const; //Function to output the data contained in each node. //Postcondition: none int length() const; //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; int front() const; //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, the program // terminates; otherwise, the first // element of the list is returned. int back() const; //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, the program // terminates; otherwise, the last // element of the list is returned. bool search(const int& searchItem) const; //Function to determine whether searchItem is in the list. //Postcondition: Returns true if searchItem is in the // list, otherwise the value false is // returned. void insertFirst(const int& newItem); //Function to insert newItem at the beginning of the list. //Postcondition: first points to the new list, newItem is // inserted at the beginning of the list, // last points to the last node in the list, // and count is incremented by 1. void insertLast(const int& newItem); //Function to insert newItem at the end of the list. //Postcondition: first points to the new list, newItem // is inserted at the end of the list, // last points to the last node in the // list, and count is incremented by 1. void deleteNode(const int& 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, last // points to the last node of the updated // list, and count is decremented by 1. linkedList(); //Default constructor //Initializes the list to an empty state. //Postcondition: first = nullptr, last = nullptr, // count = 0; linkedList(const linkedList& otherList); //copy constructor ~linkedList(); //Destructor //Deletes all the nodes from the list. //Postcondition: The list object is destroyed. private: void copyList(const linkedList& otherList); //Function to make a copy of otherList. //Postcondition: A copy of otherList is created and // assigned to this list. }; #endif #include #include "LinkedList.h" using namespace std; int main() { linkedList list; list.insertFirst(10); list.insertFirst(20); list.insertFirst(30); list.print(); list.insertLast(40); list.print(); cout << "The list has " << (list.search(20) ? "" : "not ") << "20" << endl; list.deleteNode(20); list.print(); cout << "The list has " << (list.search(20) ? "" : "not ") << "20" << endl; list.deleteNode(50); list.print(); list.deleteNode(10); list.print(); list.deleteNode(30); list.print(); list.deleteNode(40); list.print(); for (int i = 1; i < 50; i++) { if (i % 4 == 0) list.insertLast(i); } list.print(); linkedList list2(list); cout << "The copied list: " << endl; list2.print(); list.destroyList(); cout << "The destroyed list: " << endl; list.print(); system("pause"); return 0; } OUTPUT List has 3 items: [30] [20] [10] List has 4 items: [30] [20] [10] [40] The list has 20 List has 3 items: [30] [10] [40] The list has not 20 List has 3 items: [30] [10] [40] List has 2 items: [30] [40] List has 1 items: [40] List has 0 items: List has 12 items: [4] [8] [12] [16] [20] [24] [28] [32] [36] [40] [44] [48] The copied list: List has 12 items: [4] [8] [12] [16] [20] [24] [28] [32] [36] [40] [44] [48] The destroyed list: List has 0 items:

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!