Stacks Using Array

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Stacks Using Array as PDF for free.

More details

  • Words: 112
  • Pages: 1
//stacks using array #include#define MAX 10int stack[10],i,top=-1,x,ch;void push(){if(top==MAX-1)cout<< "\n Stack Overflow \n";else{cout<< "\n enter any element "; cin>>x; stack[++top]=x;}}void pop(){if(top==-1)cout<< "/n Stack Underflow";else{ x=stack[top--];cout<<"\n Poped element is \n"<<x; }}void display(){ if(top==-1) cout<<"\n Stack Underflow"; else { cout<<"\t Stack elements are ";for(i=0;i<=top;i++)cout<<"\t" <<stack[i];}}void main(){do{cout<< "\n 1.Push";cout<< "\n 2.pop";cout<< "\n 3.display";cout<< "\n 4.exit";cout<< "\n enter your choice[1..4] \n";cin>>ch;switch(ch){case 1:push();break; case 2:pop(); break;case 3:display();break;}}while(ch!=4);} //queues using arrays#include#define MAX 10int queue[20],i,front=-1,rear=-1,x,ch;void insertion() {if(rear==MAX-1)cout<<" \n Queue Overflow";else{cout<<"\n Enter any element \n";cin>>x; queue[++rear]=x;if(front==-1)front++;}}void deletion(){if (front==-1 || front==MAX)cout<<"\n Queue Underflow";else{x=queue[front++];cout<<"\n Deleted Element is:"<<x;}}void display(){if(front==-1 || front==MAX)\cout<<"\n Queue Underflow";else{cout<<"\n Queue Elements are:";for(i=front;i<=rear;i++) cout<<"\t"<>ch;switch(ch){case 1:insertion();break; case 2:deletion(); break;case 3:display(); break;}}while(ch!=4);}

Related Documents

Stacks Using Array
May 2020 1
Stacks
May 2020 3
Array
June 2020 19
Array
November 2019 29
Array
November 2019 32