Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdbool.h>
- #define SIZE 5
- // int stack[SIZE] = {1,2,3,4,5,6,7,8,9,10};
- int stack[SIZE-1];
- int top = -1;
- bool isEmpty()
- {
- return stack[0] == NULL ? true : false;
- }
- bool isFull()
- {
- return top == SIZE-1 ? true : false;
- }
- void push()
- {
- int val;
- if(isFull() == false)
- {
- printf("Enter Value: ");
- scanf("%d", &val);
- stack[top+1] = val;
- top+=1;
- }
- else
- {
- printf("\n\n\nFull");
- }
- }
- void pop()
- {
- if(!isEmpty()){
- stack[top] = NULL;
- top-=1;
- }
- }
- void peek()
- {
- printf("\n Top peek element is %d\n", stack[top]);
- }
- void display()
- {
- int i=0;
- printf("\n");
- for(i=0; stack[i] != NULL; i++)
- {
- printf(" %d -", stack[i]);
- }
- printf("\b\b\b\b\n");
- }
- int main()
- {
- while(1)
- {
- int choice;
- printf("MENU \n 1. Push \n 2. Pop \n 3. Peak \n 4. Exit \n");
- scanf("%d", &choice);
- if(choice == 1)
- {
- push();
- }
- else if(choice == 2)
- {
- pop();
- }
- else if(choice == 3)
- {
- peek();
- }
- else if(choice == 4)
- {
- exit(1);
- }
- display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement