#include using namespace std; class linkedListClass { public: linkedListClass(int newvalue) { dvalue=newvalue; next = NULL; } linkedListClass(int newvalue, linkedListClass *newNext) { dvalue=newvalue; next = newNext; } int getdvalue() { return (dvalue); } void addAfter(int newvalue) { linkedListClass *newnode = new linkedListClass(newvalue); newnode -> next = next; next = newnode; } void printlist() { cout << "\tcurrent node is " << dvalue << endl; if (next != NULL) next->printlist(); } private: int dvalue; linkedListClass *next; }; class realList { public: realList() { first = NULL; } realList(int nodevalue) { first = new linkedListClass(nodevalue); } void addbehind(int newvalue) { if (first == NULL) first = new linkedListClass(newvalue); else first->addAfter(newvalue); } void addinfront(int newvalue) { linkedListClass *newnode; if (first == NULL) first = new linkedListClass(newvalue); else { newnode = new linkedListClass(newvalue, first); first = newnode; } } int getdvalue() { if (first == NULL) return -1; else return(first->getdvalue()); } void printlist() { if (first == NULL) cout << "The List is currently empty.\n"; else { cout << "\nHere is the current list: \n"; first->printlist(); } } private: linkedListClass *first; }; int main() { realList *myList; int option_selected = 0, input_Number; myList= new realList(); while(option_selected != 4){ cout << "\n\nPlease enter one of the following choices: \n"; cout << "1. Enter a new number to add after the first Element. \n"; cout << "2. Enter a new number to add before the first Element. \n"; cout << "3. Display all numbers entered so far from first to last. \n"; cout << "4. Exit this program.\n"; cout << "Please enter the number of your choice: "; cin >> option_selected; switch (option_selected) { case 1: cout << "Enter the number to add after the first element: "; cin >> input_Number; myList->addbehind(input_Number); break; case 2: cout << "Enter the number to add before the first element: "; cin >> input_Number; myList->addinfront(input_Number); break; case 3: myList->printlist(); break; case 4: cout << "Goodbye!!!\n\n"; break; default: cout << "Error. Please enter a number from 1 to 4"; } } return 0; }