#include
#include
void push(int st[],int data,int &top);
void disp(int st[],int &top);
int pop(int st[],int &top);
int flg=0;
int top=-1,tos=-1;
int st[50];
void push(int st[],int data,int &top)
{
if(top==50-1)
flg=0;
else
{
flg=1;
top++;
st[top]=data;
}
}
int pop(int st[],int &top)
{
int pe;
if(top==-1)
{
pe=0;
flg=0;
}
else
{
flg=1;
pe=st[top];
top--;
}
return(pe);
}
void disp(int st[],int &top)
{
int i;
if(top==-1)
{
printf("\nStack is Empty");
}
else
{
for(i=top;i>=0;i--)
printf("\t%d",st[i]);
}
}
void main()
{
int dt,opt;
int q=0;
clrscr();
printf("This Program Is Used to Perform PUSH & POP operations On Stack");
printf("\n\n\tMain Menu.........");
printf("\n\n1.Push");
printf("\n\n2.Pop");
printf("\n\n3.Exit");
do
{
printf("\n\n\tEnter Your Choice 1-3:");
scanf("%d",&opt);
switch(opt)
{
case 1:
printf("\nEnter the Element to be Push:");
scanf("%d",&dt);
push(st,dt,tos);
if(flg==1)
{
printf("\nAfter Inserting the Element, Stack is:\n\n");
disp(st,tos);
if(tos==50-1)
printf("\nStack is Now Full");
}
else
printf("\nStack Overflow Insertion Not Possible");
break;
case 2:
dt=pop(st,tos);
if(flg==1)
{
printf("\n\tData Deleted From the Stack is:%d\n",dt);
printf("\n\tAfter Deleting the Element from the stack is:\n\n");
disp(st,tos);
}
else
printf("\nStack Empty,Deletio Not Possible:");
break;
case 3:
q=1;
break;
default:printf("\nWrong Choice Enter 1-3 Only");
}
}while(q!=1);
}
OUTPUT
Main Menu.........
1.push
2.pop
3.exit
Enter your choice 1-3:1
Enter the element to be push:4
After inserting the elements,stack is:
4
Enter your choice 1-3:1
Enter the element to be push:7
After inserting the elements,stack is:
7 4
Enter your choice 1-3:1
Enter the element to be push:4
what ever you assume
Explain The merits of using a deque to implement a stack in data structure
/* C program to implement stack. Stack is a LIFO data strcuture LIFO - Last in First Out Perform PUSH(insert operation), POP(Delete operation) and Display stack */#include #include #define MAXSIZE 5struct stack /* Structure definition for stack */{int stk[MAXSIZE];int top;};typedef struct stack STACK;STACK s;/* Function declaration/Prototype*/void push (void);int pop(void);void display (void);void main (){int choice;int option = 1;clrscr ();s.top = -1;printf ("STACK OPERATION\n");while (option){printf ("--------------\n");printf (" 1 -> PUSH \n");printf (" 2 -> POP \n");printf (" 3 -> DISPLAY \n");printf (" 4 -> EXIT \n");printf ("--------------\n");printf ("Enter your choice\n");scanf ("%d", &choice);switch (choice){case 1: push();break;case 2: pop();break;case 3: display();break;case 4: return;}fflush (stdin);printf ("Do you want to continue(Type 0 or 1)?\n");scanf ("%d", &option);}}/*Function to add an element to the stack*/void push (){int num;if (s.top -1){printf ("Stack is empty\n");return;}else{printf ("\nThe status of the stack is\n");for (i = s.top; i >= 0; i-){printf ("%d\n", s.stk[i]);}}printf ("\n");}byankit shukla
yes
Delete is mostly commonly known as pop in stack. The last element inserted into the stack is removed from the stack. Here is an illustration:Consider the stack with the elements 1,2,3,4 inserted in order.1->2->3->4\topThe top of the stack will be pointing to 4. When pop operation is performed, 4 is removed from the stack and the top is made to point to 3. The stack then becomes:1->2->3\top
Stack implementations allow us to easily implement backtracking algorithms.
stack abstract datatype
int top=-1; int stack[10];
what ever you assume
First, you see the menu. The rest depends on what you choose from the menu.
there are two operations you can do with a STACK one is PUSH operation and the other is POP operation
Yes it is possible to implement stack and queue using linked list
In order to write a program to convert stack into queue using c language you must be able to identify the proper program. Having a special certification in programing will be beneficial as well to make sure you recognize the proper queues for the programs.
Explain The merits of using a deque to implement a stack in data structure
chk out the following link showing you how to implement stack. Though it is a c++ implementation it may still help you. http://thetechnofreaks.com/2011/10/26/4-creating-a-stack/#ixzz1bvp8FXdb
/* C program to implement stack. Stack is a LIFO data strcuture LIFO - Last in First Out Perform PUSH(insert operation), POP(Delete operation) and Display stack */#include #include #define MAXSIZE 5struct stack /* Structure definition for stack */{int stk[MAXSIZE];int top;};typedef struct stack STACK;STACK s;/* Function declaration/Prototype*/void push (void);int pop(void);void display (void);void main (){int choice;int option = 1;clrscr ();s.top = -1;printf ("STACK OPERATION\n");while (option){printf ("--------------\n");printf (" 1 -> PUSH \n");printf (" 2 -> POP \n");printf (" 3 -> DISPLAY \n");printf (" 4 -> EXIT \n");printf ("--------------\n");printf ("Enter your choice\n");scanf ("%d", &choice);switch (choice){case 1: push();break;case 2: pop();break;case 3: display();break;case 4: return;}fflush (stdin);printf ("Do you want to continue(Type 0 or 1)?\n");scanf ("%d", &option);}}/*Function to add an element to the stack*/void push (){int num;if (s.top -1){printf ("Stack is empty\n");return;}else{printf ("\nThe status of the stack is\n");for (i = s.top; i >= 0; i-){printf ("%d\n", s.stk[i]);}}printf ("\n");}byankit shukla
Heap is a data-structure, it cannot implement anything. On the other hand, it is true that: 1. Recursive routines might use heap. 2. You can use dynamic memory allocation (heap), to implement a stack; and use the stack to implement recursion.