Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #define size 10
  4. using namespace std;
  5. int data[size];
  6. int top;
  7.  
  8. void push(int item){
  9.     data[top]=item;
  10.     top++;
  11. }
  12.  
  13. int pop(){
  14.     top--;
  15.     return data[top];
  16. }
  17. int peak(){
  18.     int peakvalue;
  19.     top--;
  20.     peakvalue = data[top];
  21.     top++;
  22.     return peakvalue;
  23. }
  24.  
  25. int isempty(){
  26.     if (top==0){
  27.     return 1;
  28.     }
  29.     else
  30.     {
  31.     return 0;
  32.     }
  33. }
  34. int main()
  35. {
  36.     int choice;
  37.     printf("1-for push\n");
  38.     printf("2-for pop\n");
  39.     printf("3-for peak\n");
  40.     printf("4-for check empty or not\n");
  41.     while(1){
  42.     printf("please make your selection\n");
  43.     scanf("%d",&choice);
  44.         if(choice==1){
  45.            int item;
  46.            printf("enter the item to be pushed?\n");
  47.            scanf("%d",&item);
  48.            push(item);
  49.         }
  50.         else if(choice==2){
  51.             int poped;
  52.             poped= pop();
  53.             printf("%d\n",poped);
  54.         }
  55.         else if(choice==3){
  56.             int peaked;
  57.             peaked = peak();
  58.             printf("%d\n",peaked);
  59.         }
  60.         else if(choice==4){
  61.             int poped;
  62.             poped= isempty();
  63.             printf("%d\n",poped);
  64.         }
  65.  
  66.     }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement