{"id":487,"date":"2021-06-08T16:49:41","date_gmt":"2021-06-08T16:49:41","guid":{"rendered":"https:\/\/xcodeph.net\/?page_id=487"},"modified":"2021-06-09T00:38:05","modified_gmt":"2021-06-09T00:38:05","slug":"stacks","status":"publish","type":"page","link":"https:\/\/xcodeph.net\/index.php\/stacks\/","title":{"rendered":"Stacks"},"content":{"rendered":"\n<h2><strong>Stacks<\/strong><\/h2>\n\n\n\n<p>Is a collection of items that exhibits the behavior that the last item in is the first item out Last-in-First-out (LIFO). Also, consist of a linear or sequence of all insertions and deletion is made at one end, called the top of the stack.<\/p>\n\n\n\n<h2><strong>Stack Operation<\/strong><\/h2>\n\n\n\n<p><strong>push<\/strong><\/p>\n\n\n\n<p><br>The insertion (or addition) stacks operation. Pushing an element to a stack will add the new element at the top. After every push operation, the top is incremented by one. If the array is full and no new element can be accommodated, then the stack overflow condition occurs.<\/p>\n\n\n\n<p><br><strong>pop<\/strong><\/p>\n\n\n\n<p><br>The deletion (or remove) stacks operation. After every pop operation, the stack is decremented by one. If there is no element in the stack (empty stack) and the pop operation is performed then the stack underflow condition occurs.<\/p>\n\n\n\n<p><strong>top<\/strong><\/p>\n\n\n\n<p><br>Place where insertion and deletion takes place. Collection of data items can only be accessed in this location.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Please watch video for further discussion on STACKS<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"C++ Data Structure Stack - Part 1\" width=\"771\" height=\"578\" src=\"https:\/\/www.youtube.com\/embed\/FJiTRUIHzOk?list=PLm0umdRavftZ39TEjqgWiY-QUq1yg0KUW\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><strong>Stack Implementation using Standard Library Functions<\/strong><\/p>\n\n\n\n<p><strong>Program 1<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\/\/stack array implementation\n\/\/libraries\n#include &lt;iostream>\n#include &lt;stack>\nusing namespace std;\nint main()\n{\n\tint i,x;\n\tstack&lt;int> nums;\n\tcout &lt;&lt; \"stack size\"&lt;&lt;nums.size()&lt;&lt;endl;\n\tnums.push(11);\n\tnums.push(22);\n\tnums.push(33);\n\tcout &lt;&lt; \"stack size\"&lt;&lt;nums.size()&lt;&lt;endl;\n\tcout &lt;&lt; \"top  \" &lt;&lt; nums.top()&lt;&lt;endl;\n\tfor (i=nums.size();i>0;i--)\n\t{\n\t\tx=nums.top();\n\t\tcout &lt;&lt; x &lt;&lt;endl;\n\t\tnums.pop();\n\t}\n\tcout &lt;&lt; \"stack size\"&lt;&lt;nums.size()&lt;&lt;endl;\n\t\n\treturn 0;\n}<\/pre>\n\n\n\n<p><strong>Program 2<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">#include &lt;iostream>\n#include &lt;stack>\n#include &lt;string>\nusing namespace std;\nint main()\n{\n\tstack&lt;string> name;\n\tstring n;\n\tchar quest;\n\tcout &lt;&lt; \"Enter data y\/n? \";\n\tcin >> quest;\n\twhile (quest=='Y' || quest=='y')\n\t{\n\t\tcout &lt;&lt; \"Enter name \";\n\t\tcin >> n;\n\t\tname.push(n);\n\t\tcout &lt;&lt; \"enter again y\/n? \";\n\t\tcin >> quest;\n\t}\n\tcout &lt;&lt; \" size of stack \" &lt;&lt; name.size()&lt;&lt;endl;\n\twhile(!name.empty())\n\t{\n\t\tcout &lt;&lt; name.top() &lt;&lt; endl;\n\t\tname.pop();\n\t}\n\tcout &lt;&lt; \" size of stack \" &lt;&lt; name.size()&lt;&lt;endl;\n\treturn 0;\n}<\/pre>\n\n\n\n<p><strong>Program 3<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\/*\n * C++ Program to Implement Stack in Stl\n *\/\n#include &lt;iostream>\n#include &lt;stack>\n#include &lt;string>\nusing namespace std;\nint main()\n{\n    stack&lt;int> st;\n    int choice, item;\n    while (1)\n    {\n        cout&lt;&lt;\"\\n---------------------\"&lt;&lt;endl;\n        cout&lt;&lt;\"Stack Implementation in Stl\"&lt;&lt;endl;\n        cout&lt;&lt;\"\\n---------------------\"&lt;&lt;endl;\n        cout&lt;&lt;\"1.Insert \"&lt;&lt;endl;\n        cout&lt;&lt;\"2.Delete \"&lt;&lt;endl;\n        cout&lt;&lt;\"3.Size of the Stack\"&lt;&lt;endl;\n        cout&lt;&lt;\"4.Top Element\"&lt;&lt;endl;\n        cout&lt;&lt;\"5.Exit\"&lt;&lt;endl;\n        cout&lt;&lt;\"Enter your Choice: \";\n        cin>>choice;\n        switch(choice)\n        {\n        case 1:\n            cout&lt;&lt;\"Enter value to be inserted: \";\n            cin>>item;\n            st.push(item);\n            break;\n        case 2:\n            item = st.top();\n            st.pop();\n\t    cout&lt;&lt;\"Element \"&lt;&lt;item&lt;&lt;\" Deleted\"&lt;&lt;endl;\n            break;\n        case 3:\n\t    cout&lt;&lt;\"Size of the Queue: \";\n\t    cout&lt;&lt;st.size()&lt;&lt;endl;\n            break;\n        case 4:\n\t    cout&lt;&lt;\"Top Element of the Stack: \";\n\t    cout&lt;&lt;st.top()&lt;&lt;endl;\n            break;\n        case 5:\n            exit(1);\n\t    break;\n        default:\n            cout&lt;&lt;\"Wrong Choice\"&lt;&lt;endl;\n        }\n    }\n    return 0;\n}\n\n<\/pre>\n\n\n\n<p><strong>Stack Implementation (User defined function)<\/strong><\/p>\n\n\n\n<p>Video Demonstration on STACK UDF<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"C++ Data Structure - Stack (User defined function) Part 2\" width=\"771\" height=\"578\" src=\"https:\/\/www.youtube.com\/embed\/O9rIp_uf8CY?list=PLm0umdRavftZ39TEjqgWiY-QUq1yg0KUW\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><strong>Program 4<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\/\/UDF of stack using array\n\/\/operations -> push, pop, traverse(display), empty()\n#include &lt;iostream>\n#define STACK_SIZE 5\nusing namespace std;\nint stackNum[STACK_SIZE];\nint top=-1;\n\nvoid push(int);\nvoid display();\nvoid pop();\nvoid clear();\nint main()\n{\n\twhile(1)\n\t{\n\t\tint choice, num;\n\t\tsystem (\"cls\");\n\t\tcout &lt;&lt; \"STACK implementation using array\\n\";\n\t\tcout &lt;&lt; \"[1] Push\\n\";\n\t\tcout &lt;&lt; \"[2] Pop \\n\";\n\t\tcout &lt;&lt; \"[3] Traverse\\n\";\n\t\tcout &lt;&lt; \"[4] Clear\\n\";\n\t\tcout &lt;&lt; \"[5] Exit\\n\";\n\t\tcout &lt;&lt; \"Enter your choice \";\n\t\tcin >> choice;\n\t\tswitch(choice)\n\t\t{\n\t\t\tcase 1:\n\t\t\t\tcout &lt;&lt; \"Enter number \";\n\t\t\t\tcin >> num;\n\t\t\t\tpush(num);\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tpop();\n\t\t\t\tbreak;\n\t\t\tcase 3:\n\t\t\t\tdisplay();\n\t\t\t\tbreak;\n\t\t\tcase 4:\n\t\t\t\tclear();\n\t\t\t\tbreak;\n\n\t\t\tcase 5:\n\t\t\t\texit(1);\n\t\t\t\tcin.ignore();\n\t\t\tdefault:\n\t\t\t\tcout &lt;&lt;\"error\";\n\t\t\t\tbreak;\n\t\t}\n\t\tcin.ignore();\n\t}\n\tcin.ignore();\n\treturn 0;\n}\nvoid push(int n)\n{\n\tif (top==STACK_SIZE-1)\n\t\tcout&lt;&lt; \"stack is full \\n\";\n\telse\n\t\tstackNum[++top]=n;\n}\nvoid display()\n{\n\tif (top==-1)\n\t\tcout &lt;&lt; \"stack is empty\";\n\telse\n\t\tfor (int i=top; i>=0;i--)\n\t\t\tcout &lt;&lt; stackNum[i] &lt;&lt; endl;\n}\nvoid pop()\n{\n\tif (top==-1)\n\t\tcout &lt;&lt; \"Stack is empty \\n\";\n\telse\n\t\tcout &lt;&lt; \"You pop the value \"&lt;&lt;stackNum[top--];\n\n}\nvoid clear()\n{\n\ttop=-1;\n\n}<\/pre>\n\n\n\n<p><strong>Program 5<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\/\/UDF of stack using array\n\/\/operations -> push, pop, traverse(display), isempty(), isfull\n#include &lt;iostream>\n#define STACK_SIZE 5\nusing namespace std;\nvoid display(int[]);\nvoid push(int,int[]);\nvoid pop(int[]);\nvoid clear(int[]);\nbool isfull(int[]);\nbool isempty(int[]);\nint main()\n{\n\tint stackNum[STACK_SIZE]={};\n\twhile(1)\n\t{\n\t\tint choice, num;\n\t\tsystem (\"cls\");\n\t\tcout &lt;&lt; \"STACK implem using array\\n\";\n\t\tcout &lt;&lt; \"[1] Push\\n\";\n\t\tcout &lt;&lt; \"[2] Pop \\n\";\n\t\tcout &lt;&lt; \"[3] Traverse\\n\";\n\t\tcout &lt;&lt; \"[4] Clear\\n\";\n\t\tcout &lt;&lt; \"[5] Exit\\n\";\n\t\tcout &lt;&lt; \"Enter your choice \";\n\t\tcin >> choice;\n\t\tswitch(choice)\n\t\t{\n\t\t\tcase 1:\n\t\t\t\tif (!isfull(stackNum))\n\t\t\t\t{\n\t\t\t\t\tcout &lt;&lt; \"\\nEnter n \";\n\t\t\t\t\tcin >> num;\n\t\t\t\t\tpush(num,stackNum);\n\t\t\t\t\tdisplay(stackNum);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tcout &lt;&lt; \"stack is full \";\n\t\t\t\t}\t\n\t\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tif (!isempty(stackNum))\n\t\t\t\t{\n\t\t\t\t\tpop(stackNum);\n\t\t\t\t\tdisplay(stackNum);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tcout &lt;&lt; \"stack is empty\\n\";\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 3:\n\t\t\t\t\tdisplay(stackNum);\n\t\t\t\t\tbreak;\n\t\t\tcase 4:\n\t\t\t\tclear(stackNum);\n\t\t\t\tdisplay(stackNum);\n\t\t\t\tbreak;\n\t\t\tcase 5:\n\t\t\t\texit(1);\n\t\t\t\tcin.ignore();\n\t\t\tdefault:\n\t\t\t\tcout &lt;&lt;\"error\";\n\t\t\t\tbreak;\n\t\t}\n\t\tcin.ignore();\n\t}\n\tcin.ignore();\n\treturn 0;\n}\nvoid push(int num, int n[])\n{\n\tfor (int i=STACK_SIZE-1; i>0;i--)\n\t{\n\t\tn[i]=n[i-1];\n\t}\n\tn[0]=num;\n\tcout &lt;&lt; \"you push the value \" &lt;&lt; num &lt;&lt; \" into the stack\"&lt;&lt;endl;\n}\nvoid pop(int n[])\n{\n\tfor (int i=0; i&lt;STACK_SIZE-1;i++)\n\t{\n\t\tn[i]=n[i+1];\n\t}\n\tn[STACK_SIZE-1]=0;\n}\nvoid display(int n[])\n{\n\tfor (int i =0; i&lt;STACK_SIZE;i++)\n\t{\n\t\tcout &lt;&lt; \"[\" &lt;&lt; i &lt;&lt; \"]\" &lt;&lt; n[i] &lt;&lt; endl;\n\t}\n}\nbool isfull(int n[])\n{\n\tif (n[STACK_SIZE-1]==0)\n\t\treturn false;\n\treturn true;\n}\nbool isempty(int n[])\n{\n\tif (n[0]==0)\n\t\treturn true;\n\treturn false;\n}\nvoid clear(int n[])\n{\n\tfor (int i=0; i&lt;STACK_SIZE;i++)\n\t\tn[i]=0;\n}<\/pre>\n\n\n\n<p><strong>Stack Implementation using Linked List<\/strong><\/p>\n\n\n\n<p><strong>Program 6<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\/\/UDF of stack using linked list\n\/\/operations -> push, pop, traverse(display)\n#include &lt;iostream>\n#include &lt;iomanip>\nusing namespace std;\nstruct node{\n\tint data;\n\tnode *next;\n}*top;  \n\nvoid pop();\nvoid push(int);\nvoid display();\nint main()\n{\n\twhile(1)\n\t{\n\t\tint choice, num;\n\t\tsystem (\"clear\");\n\t\tcout &lt;&lt; \"STACK implem using linked list\\n\";\n\t\tcout &lt;&lt; \"[1] Push\\n\";\n\t\tcout &lt;&lt; \"[2] Pop \\n\";\n\t\tcout &lt;&lt; \"[3] Traverse\\n\";\n\t\tcout &lt;&lt; \"[4] Exit\\n\";\n\t\tcout &lt;&lt; \"Enter your choice \";\n\t\tcin >> choice;\n\t\tswitch(choice)\n\t\t{\n\t\t\tcase 1:\n\t\t\t\tcout &lt;&lt; \"Enter n: \";\n\t\t\t\tcin >> num;\n\t\t\t\tpush(num);\n\t\t\t\tdisplay();\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tpop();\n\t\t\t\tbreak;\n\t\t\tcase 3:\n\t\t\t\tdisplay();\n\t\t\t\tbreak;\n\t\t\tcase 4:\n\t\t\t\texit(1);\n\t\t\t\tcin.ignore();\n\t\t\tdefault:\n\t\t\t\tcout &lt;&lt;\"error\";\n\t\t\t\tbreak;\n\t\t}\n\t\tcin.ignore().get();\n\t}\n\tcin.ignore().get();\n\treturn 0;\n}\nvoid push(int n)\n{\n\tnode *p = new node;\n\tp->data=n;\n\tif (top==NULL)\n\t\tp->next=NULL;\n\telse\n\t\tp->next=top;\n\ttop=p;\n}\nvoid pop()\n{\n\tif (top==NULL)\n\t\tcout &lt;&lt; \"stack is empty\\n\";\n\telse\n\t{\n\t\tnode *tmp = top;\n\t\tcout &lt;&lt; \"you poped the value \" &lt;&lt; top->data &lt;&lt; endl;\n\t\ttop=top->next;\n\t\ttmp->next=NULL;\n\t\tdelete(tmp);\n\t}\n}\nvoid display()\n{\n\tnode *p;\n\tif (top==NULL)\n\t\tcout &lt;&lt; \"Nothing to display\\n\";\n\telse\n\t{\n\t\tcout &lt;&lt; \"Stack elements \\n\";\n\t\tcout &lt;&lt; setw(10) &lt;&lt; \"POINTER\"\n\t\t\t&lt;&lt; setw(20) &lt;&lt; \"VALUE\"\n\t\t\t&lt;&lt; setw(30) &lt;&lt; \"NEXT\"\n\t\t\t&lt;&lt; endl;\n\t\t\n\t\tp=top;\n\t\twhile(p!=NULL)\n\t\t{\n\t\t\tcout &lt;&lt; setw(10) &lt;&lt; p\n\t\t\t\t&lt;&lt; setw(20) &lt;&lt; p->data\n\t\t\t\t&lt;&lt; setw(30) &lt;&lt; p->next\n\t\t\t&lt;&lt; endl;\n\t\t\tp=p->next;\n\t\t}\n\t\n\t}\n\n}\n<\/pre>\n\n\n\n<p><strong>STACK Implementation using OOP <\/strong>(Using Array)<\/p>\n\n\n\n<p><strong>Program 7<\/strong><\/p>\n\n\n\n<p><strong>Filename: IntStack.h<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\nclass IntStack {\n\tprivate:\n\t\tint *stackArray;\n\t\tint stackSize;\n\t\tint top;\n\tpublic:\n\t\tIntStack(int size);\n\t\tvoid push(int num);\n\t\tvoid pop(int &amp;num);\n\t\tbool isFull();\n\t\tbool isEmpty();\n};<\/pre>\n\n\n\n<p><strong>Filename: IntStack.cpp<\/strong><\/p>\n\n\n\n<p><strong>Program 8<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\n#include &lt;iostream>\n#include \"IntStack.h\"\nusing namespace std;\n\t\/\/ Constructor\n\tIntStack::IntStack(int size)\n\t{\n\t\tstackArray = new int[size];\n\t\tstackSize = size;\n\t\ttop = -1;\n\t}\n\n\n\t\/\/*************************************************\n\t\/\/ Member function push pushes the argument onto\n\t\/\/ the stack.\n\t\n\tvoid IntStack::push(int num)\n\t{\n\t\tif (isFull())\n\t\t\t{\n\t\t\tcout &lt;&lt; \"The stack is full.\\n\";\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ttop++;\n\t\t\tstackArray[top] = num;\n\t\t\t}\n\t}\n\n\t\/\/****************************************************\n\t\/\/ Member function pop pops the value at the top\n\t\/\/ of the stack off, and copies it into the variable\n\t\/\/ passed as an argument.\n\t\n\tvoid IntStack::pop(int &amp;num)\n\t{\n\t\tif (isEmpty())\n\t\t\t{\n\t\t\t\t\tcout &lt;&lt; \"The stack is empty. n\";\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tnum = stackArray[top];\n\t\t\ttop--;\n\t\t\t}\n\t}\n\n\t\n\t\/\/***************************************************\n\t\/\/ Member function isFull returns true if the stack\n\t\/\/ is full, or false otherwise.\n\t\n\tbool IntStack::isFull()\n\t{\n\t\tbool status;\n\t\tif (top == stackSize -  1)\n\t\t\t\tstatus = true;\n\t\telse\n\t\t\t\tstatus = false;\n\t\treturn status;\n\t}\n\n\n\n\t\/\/****************************************************\n\t\/\/ Member function isEmpty returns true if the stack\n\t\/\/ is empty, or false otherwise.\n\t\n\tbool IntStack::isEmpty()\n\t{\n\t\tbool status;\n\t\tif (top == -1)\n\t\t\tstatus = true;\n\t\telse\n\t\t\tstatus = false;\n\t\treturn status;\n\t}\n\n\n\n\tint main()\n\t{\n\t\tIntStack stack(5);\n\t\tint catchVar;\n\t\tcout &lt;&lt; \"Pushing 5\\n\";\n\t\tstack.push(5);\n\t\tcout &lt;&lt; \"Pushing 10\\n\";\n\t\tstack.push(10);\n\t\tcout &lt;&lt; \"Pushing 15\\n\";\n\t\tstack.push(15);\n\t\tcout &lt;&lt; \"Pushing 20\\n\";\n\t\tstack.push(20);\n\t\tcout &lt;&lt; \"Pushing 25\\n\";\n\t\tstack.push(25);\n\t\t\n\t\tcout &lt;&lt; \"Popping..\\n\";\n\t\tstack.pop(catchVar);\n\t\tcout &lt;&lt; catchVar &lt;&lt; endl;\n\t\tstack.pop(catchVar);\n\t\tcout &lt;&lt; catchVar &lt;&lt; endl;\n\t\tstack.pop(catchVar);\n\t\tcout &lt;&lt; catchVar &lt;&lt; endl;\n\t\tstack.pop(catchVar);\n\t\tcout &lt;&lt; catchVar &lt;&lt; endl;\n\t\tstack.pop(catchVar);\n\t\tcout &lt;&lt; catchVar &lt;&lt; endl;\n\t\n\t}<\/pre>\n\n\n\n<p><strong>STACK Implementation using OOP <\/strong>(Using Linked list)<\/p>\n\n\n\n<p><strong>Program 9<\/strong><\/p>\n\n\n\n<p><strong>Filename: DynIntStack.h<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\nclass DynIntStack\n{\n\tprivate:\n\t\tstruct StackNode\n\t\t{\n\t\t\tint value;\n\t\t\tStackNode *next;\n\t\t};\n\t\tStackNode *top;\n\tpublic:\n\t\tDynIntStack()\n\t\t\t{ top = NULL; }\n\t\tvoid push(int num);\n\t\tvoid pop(int &amp;num);\n\t\tbool isEmpty();\n};<\/pre>\n\n\n\n<p><strong>Program 10<\/strong><\/p>\n\n\n\n<p><strong>Filename: DynIntStack.cpp<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\n#include &lt;iostream>\n#include \"DynIntStack.h\"\nusing namespace std;\n\n\tvoid DynIntStack::push(int num)\n\t{\n\t\tStackNode *newNode;\n\t\t\/\/ Allocate a new node &amp; store Num\n\t\tnewNode = new StackNode;\n\t\tnewNode -> value = num;\n\t\n\t\t\/\/ If there are no nodes in the list\n\t\t\/\/ make newNode the first node\n\t\t\n\t\tif (isEmpty())\n\t\t{\n\t\t\ttop = newNode;\n\t\t\tnewNode ->next = NULL;\n\t\t}\n\t\telse \/\/ Otherwise, insert NewNode before top\n\t\t{\t\tnewNode ->next =top;\n\t\t\t\ttop = newNode;\n\t\t}\n\t}\n\t\t\n\t\t\/\/****************************************************\n\t\t\/\/ Member function pop pops the value at the top\n\t\t\/\/ of the stack off, and copies it into the variable\n\t\t\/\/ passed as an argument.\n\t\t\n\t\tvoid DynIntStack::pop(int &amp;num)\n\t\t{\n\t\t\tStackNode *temp;\n\t\t\tif (isEmpty())\n\t\t\t\t{\n\t\t\t\tcout &lt;&lt; \"The stack is empty.\\n\";\n\t\t\t\t}\n\t\t\t\telse \/\/ pop value off top of stack\n\t\t\t\t{\n\t\t\t\t\tnum = top ->value;\n\t\t\t\t\ttemp = top ->next;\n\t\t\t\t\tdelete top;\n\t\t\t\t\ttop = temp;\n\t\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\t\/\/****************************************************\n\t\t\/\/ Member function isEmpty returns true if the stack\n\t\t\/\/ is empty, or false otherwise.\n\t\t\n\t\tbool DynIntStack::isEmpty()\n\t\t{\n\t\t\tbool status;\n\t\t\tif (!top)\n\t\t\t\tstatus = true;\n\t\t\telse\n\t\t\t\tstatus = false;\n\t\t\treturn status;\n\t\t}\n\t\t\n\t\n\n\n\tint main()\n\t{\n\t\tDynIntStack stack;\n\t\tint catchVar;\n\t\tcout &lt;&lt; \"Pushing 5\\n\";\n\t\tstack.push(5);\n\t\tcout &lt;&lt; \"Pushing 10\\n\";\n\t\tstack.push(10);\n\t\tcout &lt;&lt; \"Pushing 15\\n\";\n\t\tstack.push(15);\n\t\t\n\t\tcout &lt;&lt; \"Popping...\\n\";\n\t\tstack.pop(catchVar);\n\t\tcout &lt;&lt; catchVar &lt;&lt; endl;\n\t\tstack.pop(catchVar);\n\t\tcout &lt;&lt; catchVar &lt;&lt; endl;\n\t\tstack.pop(catchVar);\n\t\tcout &lt;&lt; catchVar &lt;&lt; endl;\n\t\tcout &lt;&lt; \"\\nAttempting to pop again... \";\n\t\tstack.pop(catchVar);\n\t\n\t\t\n\t}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Stacks Is a collection of items that exhibits the behavior that the last item in is the first item out Last-in-First-out (LIFO). Also, consist of a linear or sequence of all insertions and deletion is made at one end, called the top of the stack. Stack Operation push The insertion (or addition) stacks operation. Pushing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/xcodeph.net\/index.php\/wp-json\/wp\/v2\/pages\/487"}],"collection":[{"href":"https:\/\/xcodeph.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/xcodeph.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/xcodeph.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xcodeph.net\/index.php\/wp-json\/wp\/v2\/comments?post=487"}],"version-history":[{"count":9,"href":"https:\/\/xcodeph.net\/index.php\/wp-json\/wp\/v2\/pages\/487\/revisions"}],"predecessor-version":[{"id":504,"href":"https:\/\/xcodeph.net\/index.php\/wp-json\/wp\/v2\/pages\/487\/revisions\/504"}],"wp:attachment":[{"href":"https:\/\/xcodeph.net\/index.php\/wp-json\/wp\/v2\/media?parent=487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}