Insert item in stack
Advertisements
Push Operation
In case of stack Insertion of any item in stack is called push. In stack any item is inserted from top of the stack, When you insert any item in stack top will be increased by 1.
Algorithm for push
- Initialization, set top=-1
- Repeat step 3 to 5 until top<Max size-1
- Read, item
- Set top=top+1
- Set stack[top]=item
- Print "stack overflow"
Example of Push Item in Stack
void push() { int item; if(top==size-1) { printf("\n stack is full"); } else { top=top+1; printf("\n\n Enter element in stack: "); scanf("%d",&s.item); s.stack[top]=s.item; } }
Google Advertisment