Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following modification to array implementation ofstack. Instead of

ID: 3616654 • Letter: C

Question

Consider the following modification to array implementation ofstack. Instead of inserting the new items in the end, let us changethe implementation to insert at the top of the array. Identify allthe operations for which code has to be changed.

initializeStack

destroyStack

isEmptyStack

isFullStack

push

top

pop

Consider the following modification to array implementation ofstack. Instead of inserting the new items in the end, let us changethe implementation to insert at the top of the array. Identify allthe operations for which code has to be changed.


initializeStack


destroyStack


isEmptyStack


isFullStack


push


top


pop

Explanation / Answer

       #include<iostream.h>
       #include<conio.h>

/* Function to display thestack elements --------------------------------------*/
void display()
{
if(top==0)
//Condition checks whether stack is empty or not
  cout<<"Stack is empty"<<endl;
else
{
  //Displays the elements of stack when it is notempty
  cout<<"The elements in the stackare:"<<endl;
  for(int i=top-1;i>=0;i--)
   cout<<s[i]<<" ";
}
cout<<endl;
}

void main() //mainfunction
{
int ch;
clrscr();
do
{
  menu();
  cout<<"Enter your choice"<<endl;
  cin>>ch;

  if(ch==1)
   push();
  else if(ch==2)
   pop();
  else if(ch==3)
   display();
  else if(ch==4)
   break;
  else
   cout<<"Please enter the rightchoice"<<endl;