Homework 9 - Linked Lists

The purpose of this assignment is to create a linked list to store elements using Object Oriented programming methods. This will be accomplished by using the template class 'Node' and creating a class template 'LinkedList' that will contain a Node template member variable head, an iteger for the list's count, and a set of member functions to implement list operations.

The Node class will contain a single element data and the address of the node containing the next element. The element for this assignment will be an integer (but it could be a double, char, or any other datatype if we wanted it to be). The Node class will also contain a a set of constructors and member functions. Use the given Node.h and Node.cpp files ( added: hw9main.cpp).

You will define the following class template LinkedList header file (LinkedList class definition w/ prototypes) and implementation file (LinkedList member function definitions). This class will have the following:

You may add additional functions to support the above functions if you wish, but you must have the above functions implemented to receive full credit on the assignment.

Your main function will implement the following menu:

      Welcome to the Linked List Menu
  ===========================================
  1.  Search for an element in the list
  2.  Add an element to the front of the list
  3.  Add an element to the back of the list
  4.  Add an element at position 
  5.  Delete an element from the list
  6.  Print the list
  7.  Clear the list

  0.  Exit
  ===========================================
  Enter Choice: 

Before you enter the menu loop, instantiate a LinkedList<int> object. This will be the list object you will use within main.

If the user selects Options 1,5-7 before adding data to the list (when the head is NULL), tell them the list is empty and return to the selection prompt for the menu.

Option 1 will prompt the user for an element to search for and call search(valueToSearchFor). If the returned value is 0, print out that the element was not found. Otherwise, print out that the element was found at the returned value position.

Option 2, and 3 will behave as described within the menu. It wont prompt the user for a position, only for a new element to insert, and read it in. It will then call insert(atPosition, newElement). The front position will be 1, and the back position will always be count+1.

Option 4 will prompt the user for a position to insert at and for a new element to insert, read the values in. It will then call insert(atPosition, newElement).

Option 5 will prompt the user for an element to remove and call remove(elemToRemove) and output whether the element was successfully removed or not.

Option 6 will call print().

Option 7 will call clear().

Option 0 will call clear().

Each option that reads in an element should use input failure detection when the user accidently types in an incorrect datatype.

// used in hw8.cpp
cout << "Please enter an element: ";
cin >> elem;
while(cin.fail()) {
  cin.clear(); 
  cin.ignore(255, '\n');
  cout << "Invalid element entered. Please enter a new element: ";
  cin >> elem;
}

Have your completed source code in the required directory, otherwise I will not be able to extract your homework. It is important that the directory and filename are exact.
~/2020_S19/wk9/hw9.cpp
~/2020_S19/wk9/Node.h
~/2020_S19/wk9/Node.cpp
~/2020_S19/wk9/LinkedList.h
~/2020_S19/wk9/LinkedList.cpp