ST12

#include <iostream>
using namespace std;
int stack[100], top=-1, size;
void push(int &top,int n)
{
cout << "";
}
void push()
{
  if(top==size-1)
    cout<<"Stack Overflow"<<endl;
  else
  {
    top++;
    cin>>stack[top];
  }
}
void pop()
{
  if(top==-1)
    cout<<"Stack underflow"<<endl;
  else
  {
    cout<<"deleted element is"<<stack[top]<<endl;
    top--;
  }
}
void print()
{
  int i;
  for(i=top;i>=0;i--)
    cout<< " " <<stack[i]<<"";
  cout<<endl;
}
int main()
{
  char opt;
  int o;
  cin>>size;
  do
  {
    cin>>o;
    switch(o)
    {
      case 1:
        {
          push();
          break;
        }
      case 2:
        {
          pop();
          break;
        }
    }
    cin>>opt;
  }while(opt=='y');
  print();
  return 0;
}

9 comments:

  1. #include iostream \\put angle brackets here
    using namespace std;
    int stack[100], top=-1, size;
    void push(int &top,int n)
    {
    cout << "";
    }
    void push()
    {
    if(top==size-1)
    cout<<"Stack Overflow"<>stack[top];
    }
    }
    void pop()
    {
    if(top==-1)
    cout<<"Stack underflow"<=0;i--)
    cout<< " " <>size;
    do
    {
    cin>>o;
    switch(o)
    {
    case 1:
    {
    push();
    break;
    }
    case 2:
    {
    pop();
    break;
    }
    }
    cin>>opt;
    }while(opt=='y');
    print();
    return 0;
    }

    ReplyDelete
  2. #include
    using namespace std;
    int stack[100], top=-1, size;
    void push(int &top,int n)
    {
    cout << "";
    }
    void push()
    {
    if(top==size-1)
    cout<<"Stack Overflow"<>stack[top];
    }
    }
    void pop()
    {
    if(top==-1)
    cout<<"Stack underflow"<=0;i--)
    cout<<" "<>size;
    do
    {
    cin>>o;
    switch(o)
    {
    case 1:
    {
    push();
    break;
    }
    case 2:
    {
    pop();
    break;
    }
    }
    cin>>opt;
    }while(opt=='y');
    print();
    return 0;
    }

    ReplyDelete
  3. #include
    using namespace std;
    int stack[100], top=-1, size;
    void push(int &top,int n)
    {
    cout <<"";
    }
    void push()
    {
    if(top==size-1)
    cout<<"Stack Overflow"<>stack[top];
    }
    }
    void pop()
    {
    if(top==-1)
    cout<<"Stack underflow"<=0;i--)
    cout<< " " <>size;
    do
    {
    cin>>o;
    switch(o)
    {
    case 1:
    {
    push();
    break;
    }
    case 2:
    {
    pop();
    break;
    }
    }
    cin>>opt;
    }while(opt=='y');
    print();
    return 0;
    }

    ReplyDelete
  4. #include
    using namespace std;
    struct node{
    int data;
    struct node *next;
    }*head=NULL,*temp,*newNode;
    void create(){
    newNode=(struct node *)malloc(sizeof(struct node));
    cin>>newNode->data;
    newNode->next=head;
    head=newNode;
    }
    void push(int &top,int n);
    void pop(){
    temp=head;
    cout<<"deleted element is"<data<<" ";
    temp=temp->next;
    }
    }

    int main() {
    int b,a;

    cin>>a;
    char c='y';
    while(c=='y'){
    int b;
    cin>>b;
    if(b==1){
    create();
    }
    else if(b==2){
    pop();
    }
    cin>>c;
    }
    return 0;
    }

    ReplyDelete
  5. here's the fix:

    cout<<"deleted element is"<<endl<<stack[top];

    ReplyDelete

SRM ELAB SOLUTUONS   DATA-STRUCTURE                                                                             **IF THE PROGRAM DON...