Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. Execute the programs (Program 8.15 and Program 8.16) given below for array. based stack and observe the output when the following operations are performed:

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
3. Execute the programs (Program 8.15 and Program 8.16) given below for array. based stack and observe the output when the following operations are performed: a) push a, push b, push c, push d, push a, push b, push c, push d, push , push d, and push f. b) push a, push b, pop, push c, push d, pop, push a, and push b c) push a, push b, pop, push c, push d, pop, push a, pop, pop, pop, and pop d) Repeat the operations for a stack implemented with link list. vold createstack () : void pueh() 21/ insert operation void pop (1) If delete operation int infu11 () 2 if eheek if ntack in ral1 bool fepmpty () ; /I obeok if stack in ruli booly voidstackt:oreatestack()iftop=1:1beolstack:isnhal()(returnbool(top=nnize-1),1 boolstack:idalmpty()(returnbool(Top=1) ) void stack: ipunh () f ohar newitem; cout "Enter item to inserted into stack" > newitom; if (ispu11 ()) I/ check whether stack is fu11 cout "Sorry, stack in fal1,"k endly, else f top = top +1// Top point to next index data [top] = newiten; //asnign new item at top // /end elso H//end push() void stack: 1 pop () f char item; if ( iskmpty ()) cout "sorry, stack is eeptyl" andl; else I //display value at top to be deleted cout npopped value :" data [topl: top = top 1; // top will hold to new index )// end if H/lend pop char stackTop () I //funetion to get top value if (isBimpty ()) cout "sorry, stack is empty" " endl; else return data [top]; 1/f end stackTop //Progran 8.16:- 11nked list based stack olass nodestackf int data; ; nodestack tnext; 11 olass stacki private: / / declaxation int datar nodestack tTop: public t 1/ declaxation of member functions void oreate (); /f aet Top to NuL. void Push() ; 1/ insert item into stack void Pop (); 1/ delete item from stack int stackTop () i /I get content at top stack bool isFrpty () i f oheck mhether stack is eapty 17 void ntackt: create () i top = Nut. ; 1 bool stack: i is Fimpty () f return bool ( top a NOH. ); 1 void stack: ipush () f nodestack *nernode; int item. cout "Insert an item: " endl; oin iteminewmode = nov (stack) ; if ( novnode an NULI) cout nCannot a 11ocate nemory.." /f add to empty atack, or to front stack f nornode->data =1 tem; nevmode-pnext = head; head = nevinode ; 1// end 1f 1 /lend puah operation votd stack: ipop () f nodestack "delnode; if (iskipty ()) cout "Sorry, stack is atil1. empty 1 "Item to be popped fros stack is: / K head->data Kendl; head = delnode-pnext; delete (delnode) : 1/t end pop int stack: a tackTop () I if (iazapty ()) cout data; \\ 58 & end check item at top \end{tabular}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions