Advertisement
Adrita

sem 2 stack lab 2

Jul 3rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int stack[5],n,element,top=-1;
  5. x:
  6. printf("enter a number within 1 to 4\n");
  7. scanf("%d",&n);
  8. while(n!=4)
  9. {
  10. if(n==1)
  11. {
  12. top++;
  13. printf("enter ur element\n");
  14. scanf("%d",&element);
  15. stack[top]=element;
  16. if(top>=5)
  17. {
  18. printf("NO SPACE TO PUSH");
  19. }
  20. goto x;
  21. }
  22. else if(n==2)
  23. {
  24. printf("%d\n",stack[top]);
  25. top--;
  26. if(top<0)
  27. {
  28. printf("nothing to pop\n");
  29. }
  30. goto x;
  31. }
  32. else if(n==3)
  33. {
  34. printf("%d\n",stack[top]);
  35. if(top<0)
  36. {
  37. printf("nothing on top\n");
  38. }
  39. goto x;
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement