/* This program is used to demonstrate the linked list data structure and its operations. The program allows the user to pick the operation that he/she wants to apply to the list. */ #include "LinkedList.h" #include using namespace std; int main() { int position; //stores the position of insertion/deletion int value; //stores the data value to be inserted char operation; //stores the operation (insert, delete, print) LinkedList L1;//creates a linked list of type integer cout << "This program demonstrates the linked list data structure and its operations." << "\nThe list capacity is 10." << endl; cout << "--------------------------------------------------------------------------------" <<endl; cout << "The program starts with one node" << endl; L1.Insert(2); position does not
//insert first element. by default the position is 1 //note that when we insert for the first time the value of //matter as you can see in the definition of Insert
L1.print();//print list cout << "--------------------------------------------------------------------------------" <<endl; cout<<endl; //loop as much as the user wishes do { cout<<"\nEnter i to insert, d to delete, p to print the list, and x to exit: "<<endl; cout<<"==================================================================="<<endl; cin>>operation; if(operation=='i') //if user chooses insert { //notify user about the index of list nodes cout<<"\nNote that the first node is considered to be at position 1."<<endl; cout<<"Enter the value then the position where you want to insert: "; cin>>value>>position; L1.Insert(value, position);
} else if(operation=='d') //if user chooses delete { cout<<"\nEnter the position of the node you want to delete: "; cin>>position; L1.Delete(position); } else if(operation=='p') //if user chooses print { L1.print(); cout << "--------------------------------------------------------------------------------" <<endl; } }while(operation !='x'); //end of do while return 0;//end main }