answersLogoWhite

0

#include<stdio.h>

#include<conio.h>

#include<math.h>

#define stack_size 5

int top,item,s1[0];

void push()

{

if(top==stack_size-1)

{

printf("stack overflow\n");

return;

}

top=top+1;

s[top]=item;

}

int pop()

{

int item_deleted;

if(top==-1)

return 0;

item_deleted=s[top--];

return item_deleted;

}

void display()

{

int i;

if(top==-1)

{

printf("stack is empty\n");

return;

}

printf("contents of the stack\n");

for(i=0;i<=top;i++)

{

printf("%d\n",s[i]);

}

}

void main()

{

int item,item_deleted,choice;

top=-1;

for(;;)

{

printf("1.push\n 2.pop\n 3.display\n 4.exit\n");

printf("enter the choice\n");

scanf("%d\n",&choice);

switch(choice)

{

case 1:Printf("enter the item to be inserted\n");

scanf("%d",&item);

push();

break;

case 2: item_deleted=pop();

if(item_deleted==0)

printf("stack is empty\n");

else

printf("item deleted = %d\n",item_deleted);

break;

case 3: display();

break;

default: exit(0);

}

}

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

What is pop in C plus plus?

"Pop" allows you to remove items off of the stack. The stack is an area in memory that contains the information of a program, such as function names and instructions, the values of variables, etc. The opposite of pop is "push". This allows you to add items to the stack.


Code palindrome in c using queue and stuck?

/** C Program to Check String is Palindrome using Stack.*/#include #include void push(char);char pop();char stack[100];int top = -1;void main(){char str[100];int i, count = 0, len;printf("Enter string to check it is palindrome or not : ");scanf("%s", str);len = strlen(str);for (i = 0; i < len; i++){push(str[i]);}for (i = 0; i < len; i++){if (str[i] == pop())count++;}if (count == len)printf("%s is a Palindrome string\n", str);elseprintf("%s is not a palindrome string\n", str);}/* Function to push character into stack */void push(char c){stack[++top] = c;}/* Function to pop the top character from stack */char pop(){return(stack[top--]);}


What is an algorithm to evaluate prefix expression using stack with example?

I HOPE THIS WILL HELP U OUT...ALGO GOES LIKE THIS: Reverrse prreffiix and evalluatte iittreverse given prefix expression;scan the reversed prefix expression;for each symbol in reversed prefixif operand thenpush its value onto stack S;if operator then {pop operand1;pop operand2;compute result = operand1 op operand2;push result back onto stack S;}return value at top of stack;AND EXAMPLE IS:Prefix: */-abc-+def Reversed: fed+-cba-/*ch action stackf push fe push f ed push f e d+ pop op1 f epop op2 fcalc &push f (d+e)- pop op1 fpop op2calc & push ((d+e)-f)c push ((d+e)-f) cb push ((d+e)-f) c ba push ((d+e)-f) c b a- pop op1 ((d+e)-f) c bpop op2 ((d+e)-f) ccalc & push ((d+e)-f) c (a-b)ch action stack/ pop op1 ((d+e)-f) cpop op2 ((d+e)-f)calc & push ((d+e)-f) ((a-b)/c)* pop op1 ((d+e)-f)pop op2calc & push ((a-b)/c)*((d+e)-f)


Algorithm of push and pop in c plus plus?

pop push c++ programming


Write a Program for Array implementation of queue and stack using exception handling.?

include &lt;iostream&gt; using namespace std; #define SIZE 10 template &lt;class StackType&gt; class stack { StackType stck[SIZE]; int topOfStack; public: void init() { topOfStack = 0; } void push(StackType ch); StackType pop(); }; template &lt;class StackType&gt; void stack&lt;StackType&gt;::push(StackType ob) { try { if(topOfStack==SIZE) throw SIZE; } catch(int) { cout &lt;&lt; "Stack is full.\n"; return; } stck[topOfStack] = ob; topOfStack++; } template &lt;class StackType&gt; StackType stack&lt;StackType&gt;::pop() { try { if( topOfStack == 0) throw 0; } catch(int) { cout &lt;&lt; "Stack is empty.\n"; return 0; } topOfStack--; return stck[topOfStack]; } int main() { stack&lt;char&gt; stack1, stack2; int i; stack1.init(); stack2.init(); stack1.push('a'); stack2.push('x'); stack1.push('b'); stack2.push('y'); stack1.push('c'); stack2.push('z'); for(i = 0; i &lt;3; i++) cout &lt;&lt; "Pop stack1: " &lt;&lt; stack1.pop() &lt;&lt; endl; for(i = 0; i &lt;4; i++) cout &lt;&lt; "Pop stack2: " &lt;&lt; stack2.pop() &lt;&lt; endl; // demonstrate double stacks stack&lt;double&gt; doubleValueStack1, doubleValueStack2; // create two stacks // initialize the stacks doubleValueStack1.init(); doubleValueStack2.init(); doubleValueStack1.push(1.1); doubleValueStack2.push(2.2); doubleValueStack1.push(3.3); doubleValueStack2.push(4.4); doubleValueStack1.push(5.5); doubleValueStack2.push(6.6); for(i = 0; i &lt;3; i++) cout &lt;&lt; "Pop doubleValueStack1: " &lt;&lt; doubleValueStack1.pop() &lt;&lt; endl; for(i = 0; i &lt;4; i++) cout &lt;&lt; "Pop doubleValueStack2: " &lt;&lt; doubleValueStack2.pop() &lt;&lt; endl; return 0; }


Stack example in c using push and pop?

http://www.osix.net/modules/article/?id=275muzzy writes "Here's some code for you kids. It demonstrates the concept of stack, implemented with a linked list mechanism to support virtually infinitely large stack sizes. Happy reading."/* Simple Dynamically Allocating Stack Implementation in C** Copyright (C) 2002 Muzzy of Worst Coders*/


Push and pop instruction of 8086 microprocessor?

I am not sure about 8086, but I can tell you the whole procedure in 8085. PUSH instruction always pushes two bytes of data i.e. total 16 bits. Example: Assume that Stack is already initialized and SP is at 2008 address location. Then PUSH B instruction will have following steps: 1) The stack pointer (SP) will be pointing to the uppermost position of the stack (actually stack works in opposite order in terms of Addresses. e.g. if SP is now at address 2008, then PUSH instruction will store the contents on 2007 &amp; 2006). 2) The contents of register B &amp; C will be saved on to the stack such that contents of register B will be at 2007 &amp; that of C will be at 2006 address location. 3) The SP is now modified to 2006.


'write a simple program for stack operation in c plus plus?

void push(int y) { if(top&gt;stackSize) { cout&lt;&lt;"stack full"&lt;&lt;endl; return; } else { top++; stack[top]=y; } } int pop() { int a; if(top&lt;=0) { cout&lt;&lt;"stack is empty"&lt;&lt;endl; return 0; } else { a=stack[top]; top--; } return(a); }


Implement a class stack which simulates the operations of the stack allowing LIFO operationsAlso implement push and pop operations for the stack?

/* 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


Write a program to store block of data in reverse order in a memory block using 8085 microprocessor?

A possible program to reverse a block of memory using the 8085... PUSH F SAVE PROCESSOR STATE - OPTIONAL PUSH B PUSH D PUSH H LXI H,{address of block} MOV D,H SAVE BLOCK ADDRESS MOV E,H MVI A,{size of block} MOV C,A SAVE BLOCK SIZE LOOP1: MOV A,M GET DATA BYTE PUSH F PUSH ON STACK DCR C DECREMENT LOOP COUNT XRA A TEST FOR END OF LOOP CMP C JNZ LOOP1 MOV H,D RESTORE BLOCK ADDRESS MOV L,E MOVE C,B RESTORE BLOCK SIZE LOOP2: POP F POP FROM STACK MOV M,A PUT DATA BYTE DCR C DECREMENT LOOP COUNT XRA A TEST FOR END OF LOOP CMP C JNZ LOOP2 POP H RESTORE PROCESSOR STATE - OPTIONAL POP D POP B POP F


Write a c program to calculate factorial of a number using stack 2write a c program to generate a Fibonacci series using stack number of Fibonacci series is input by the user?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; #include&lt;stdlib.h&gt; int stack[10],n=0; int fact(int); int pop(); void push(int); main() { int num; printf("\n FACTORIAL USING STACK IMPLEMENTATED WITH ARRAY\n"); printf("\n Enter a number whose factorial is to be found(1-9): "); scanf("%d",&amp;num); printf("\n The factorial is : %d",fact(num)); getch(); } void display() { int i; printf("\n The stack is :\n"); for(i=1;i&lt;=n;i++) { printf("%d\t",stack[i]); } } int pop() { if(n==0) { printf("\n Stack empty!Pop not possible!"); exit(1); } else { int res=stack[n]; --n; display(); return res; } } void push(int x) { if(n==9) { printf("\n Stack full!Push not possible"); exit(1); } else { n++; stack[n]=x; display(); } } int fact(int num) { if(num==2) { push(2); push(1); int res=1; display(); while(n&gt;=1) res*=pop(); return res; } else { push(num); return fact(num-1); } }


What is the pseudo code for returning the top element of a stack?

A stack is a singly-linked list where new elements are added (pushed) to the head, and existing elements are removed (popped) from the head. As such, the stack object need only maintain a pointer to the head node and implement the pop and push methods. A stripped-down implementation in C++ follows: // Forward declaration class stack; // Minimal declaration... class node { friend node * stack::pop(); node * next; }; // Minimal implementation of stack demonstrating pop implementation class stack { node * head; public: node * pop() { // store the head pointer node * popped = head; // update head pointer if not NULL if( head ) head = head.next; // return stored pointer return( popped ); } };