#include using namespace std; class linkedListclass { friend class realList; public: linkedListclass(int newvalue) { dvalue=newvalue; next = NULL; } void printlist() { cout << "current node is " << dvalue << endl; if (next != NULL) next->printlist(); else cout << "\n\n"; } private: int dvalue; linkedListclass *next; }; class realList { public: realList(int nodevalue) { first = new linkedListclass(nodevalue); last = first; } ~realList() { linkedListclass *temp; cout << "called the destructor for realList \n"; while (first != NULL) { temp = first; first = first -> next; cout << "deleting " << temp->dvalue << endl; delete temp; } } void addAtFront(int newvalue) { linkedListclass *newnode = new linkedListclass(newvalue); newnode->next = first; first = newnode; } int delFromFront() { int retval; linkedListclass *temp; retval = first->dvalue; temp = first; if (first == last) { first = last = NULL; } else first = first-> next; delete temp; return retval; } int getdvalue() { return(first->dvalue); } void printlist() { first->printlist(); } private: linkedListclass *first, *last; }; class mystack { public: mystack () { stacklist = NULL; } void push (int newvalue) { if (stacklist == NULL) stacklist = new realList(newvalue); else stacklist->addAtFront(newvalue); } int pop () { return stacklist->delFromFront(); } private: realList *stacklist; }; int main() { mystack *myList; myList= new mystack; myList->push(23); myList->push(45); myList->push(10); int delval = myList->pop(); cout << "just deleted " << delval << endl; delval = myList->pop(); cout << "just deleted " << delval << endl; delval = myList->pop(); cout << "just deleted " << delval << endl; delete myList; return 0; }