// Stack program in Data structure #include // include header file stdio.h #include // include header file stdlib.h int top=-1; void main() { int size,a[10],i,j; printf("Enter a size of stack :"); scanf("%d",&size); system("clear");
x: for(i=size-1; i>=0; i--) { printf("\n\t|"); if(top>=i) { printf("%d|",a[i]); } else printf(" |"); if(i==top) { printf("<-top"); } } printf("\n\n1.push"); printf("\n2.pop"); printf("\n3.peep "); printf("\n4.update "); printf("\n\nEnter your choice : "); int n; scanf("%d",&n); if(n==1) { if(top==size-1) { printf("\n\nStack is over flow\n"); } else { top++; printf("Entrer a value :"); scanf("%d",&a[top]); } } if(n==2) { if(top>=0) { a[top]=0; top--; } else { printf("\n\n Stack is already empty \n\n"); } } if(n==3) { printf("\nEnter a value : "); int c; scanf("%d",&c); if(c>0 && c<=top+1) { printf("%d",a[top+1-c]); } } if(n==4) { printf("\nEnter a possition : "); int c; scanf("%d",&c); printf("\nEnter a value to update : "); int u; scanf("%d",&u); if(c>0 && c<=top+1) { a[top+1-c]=u; } } printf("\n\nDo you want to continue than tap 1 :"); int b; scanf("%d",&b); if(b==1) { int x; goto x; } }
| | | | | | | | | | 1.push 2.pop 3.peep 4.update Enter your choice : 1 Entrer a value :34 Do you want to continue than tap 1 :1 | | | | | | | | |34|<-top 1.push 2.pop 3.peep 4.update Enter your choice :
4 Comments
thank you sir for that
ReplyDeleteNice bro
ReplyDeletetoo short coding bro..
ReplyDeleteNice bro...
ReplyDelete