Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #define size 10
- using namespace std;
- int data[size];
- int top;
- void push(int item){
- data[top]=item;
- top++;
- }
- int pop(){
- top--;
- return data[top];
- }
- int peak(){
- int peakvalue;
- top--;
- peakvalue = data[top];
- top++;
- return peakvalue;
- }
- int isempty(){
- if (top==0){
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int main()
- {
- int choice;
- printf("1-for push\n");
- printf("2-for pop\n");
- printf("3-for peak\n");
- printf("4-for check empty or not\n");
- while(1){
- printf("please make your selection\n");
- scanf("%d",&choice);
- if(choice==1){
- int item;
- printf("enter the item to be pushed?\n");
- scanf("%d",&item);
- push(item);
- }
- else if(choice==2){
- int poped;
- poped= pop();
- printf("%d\n",poped);
- }
- else if(choice==3){
- int peaked;
- peaked = peak();
- printf("%d\n",peaked);
- }
- else if(choice==4){
- int poped;
- poped= isempty();
- printf("%d\n",poped);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement