Document not found! Please try again

ds stacks and queues using arrays (1).pdf - Google Drive

2 downloads 202 Views 120KB Size Report
ds stacks and queues using arrays (1).pdf. ds stacks and queues using arrays (1).pdf. Open. Extract. Open with. Sign In.
/* C program to implement stacks using arrays */ #define MAX 10 void push(); void pop(); void display(); int a[MAX],top=-1; main() { int ch; clrscr(); while(1) { printf("\n 1 push an element \t 2 pop \t 3 display \t 4 exit"); printf("\n\n enter your choice"); scanf("%d",&ch); switch(ch) { case 1: push(); break; case 2: pop(); break; case 3: display(); break; case 4: exit(0); break; default: printf("\n enter a valid choice"); break; } } } void push() { int ele; if(top==MAX-1) printf("\n stack is full"); else { top=top+1; printf("\n enter an element to be inserted"); scanf("%d",&ele); a[top]=ele; }

} void pop() { if(top==-1) printf("\n stack is empty"); else { printf("\n removed element is %d",a[top]); top--; } } void display() { int i; if(top==-1) printf("\n stack is empty"); else { for(i=0;irear) { printf("\n queue is empty"); return; } else printf("\n removed element is %d",a[front]); front++; } void display() { int i; if(front==-1) printf("\n queue is empty"); else { for(i=front;i