answersLogoWhite

0


Best Answer
Stack Data Structure
1.It is a Linear Data Structure.


2.In which a data item is inserted & deleted at one end.


3.It is a Last In - First Out (LIFO) Data Structure where the data item is inserted last into the stack is the first data item to be deleted from the stack.
NOTE:


Please refer to http://www.cosc.canterbury.ac.nz/mukundan/dsal/StackAppl.html site to understand the concept of stack using java applet.


Just Copy & Paste it in your browser,but you need a Java RunTime Environment(JRE) installed onto your PC.
4.Writting a value to stack is push operation.


5.Reading a value from the stack is pop operation.


6.Once an item is popped from the stack,it is no longer available.
Algorithm
1.push operation:
if top of the stack is greater than equal to maximum number of entries into the stack,
then print "Stack is already full.Cannot add more items."
top of stack = t
increment the top of the stack


2.pop operation:
decrement top of the stack
if top <0,then print "Stack is already empty.Noitems to read."


3.call these push & pop functions declared void in the main function using the switch statement.


4.The variable top & symbolic constant stack maximum items entry number has to be declared.


User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

The Stack is a last-in first-out (LIFO) data structure. It is characterized by 2 operations:

push: add element to top of stack

pop: remove element from top of stack

A good way to remember this is with those pop can compartments in fridges. The last "pop" you added is the first pop you get (and with a pop operation ;)). You add a pop to the fridge by pushing it into the compartment (and at the top of the compartment too).

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include
void push(int);
int pop(void);
void display(void);

int main()
{
int choice=0,val=0;
do
{
printf("\n\t1.Push 2.Pop 3.Display 4.Exit\n\tSelect Your Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\tElement to be Pushed : ");
scanf("%d",&val);
push(val);
break;
case 2:
val=pop();
if(val!=-1)
printf("\tPopped Element : %d\n",val);
break;
case 3:
display();
break;
case 4:
break;
default:
printf("\tWrong Choice");
break;
}
}while(choice!=4);
return 0;
}
#define maxsize 100
int stack[maxsize];
int stacktop=0;

void push(int val)
{
if(stacktopstack[stacktop++]=val;
else
printf("Stack Overflow");
}

int pop()
{
int a;
if(stacktop>0)
{
stacktop--;
a=stack[stacktop];

return a;
}
else
{
printf("Stack is Empty");
return -1;
}
}

void display()
{
int i=0;
if(stacktop>0)
{
printf("\tElements are:");
while(i{
printf("\t%d",stack[i++]);
}
printf("\n");
}

else
printf("\tStack is Empty\n");
}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

what is stack

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the stack algorithm to push an item?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Algorithm for implementing push operation on stack?

1. If TOP = MAXSTK THEN [Stack already filled?] Print "OVERFLOW" Go to step 4 Endif 2. TOP = TOP + 1 [Increase TOP by 1] 3. Set ST[STOP] = ITEM [Insert ITEM in new TOP position] 4. End


How is the stack and stack pointer work?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Stack pointer is the pointer that points to the top of the stack or that points the item at the top of the stack and help in adding or deleting the item from the top of stack.


How do you push and pop stack elements?

algorithm of push if(top==Max-1) { cout&lt;&lt;"\n the stack is full"; } else top++; arr[top]=item; //////////////////////////////////////// algorithm of pop if(top==-1) { cout&lt;&lt;"\n the stack is empty"; } else return arr[top]; top--; }


Can stack be as a pointer?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Stack pointer is the pointer that points to the top of the stack or that points the item at the top of the stack and help in adding or deleting the item from the top of stack.


Design an algorithm to show the different operations on a stack?

Design an algorithm to show the different operations on a stack?

Related questions

Algorithm for implementing push operation on stack?

1. If TOP = MAXSTK THEN [Stack already filled?] Print "OVERFLOW" Go to step 4 Endif 2. TOP = TOP + 1 [Increase TOP by 1] 3. Set ST[STOP] = ITEM [Insert ITEM in new TOP position] 4. End


How is the stack and stack pointer work?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Stack pointer is the pointer that points to the top of the stack or that points the item at the top of the stack and help in adding or deleting the item from the top of stack.


What is the function of the stack counter?

Its not a stack counter - its a stack pointer. The stack pointer is a register that points to the top of the stack. In the Intel configuration, it points to the next item to be popped off the stack. To push an item requires that the stack pointer be decremented first, and then the item is written. The inverse operation - the pop - requires read then increment.


How do you push and pop stack elements?

algorithm of push if(top==Max-1) { cout&lt;&lt;"\n the stack is full"; } else top++; arr[top]=item; //////////////////////////////////////// algorithm of pop if(top==-1) { cout&lt;&lt;"\n the stack is empty"; } else return arr[top]; top--; }


Can stack be as a pointer?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Stack pointer is the pointer that points to the top of the stack or that points the item at the top of the stack and help in adding or deleting the item from the top of stack.


Design an algorithm to show the different operations on a stack?

Design an algorithm to show the different operations on a stack?


What to Compare and contrast between stack and queue?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.


Distinct features of queue and stack?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.


What difference between stack and queue?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.


What is queues and stacks?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.


An algorithm to Reversing the order of elements on stack S using 1 additional stacks?

// stack to contain content Stack sourceStack = new Stack(); // ... fill sourceStack with content // stack to contain reversed content Stack targetStack = new Stack(); while (!sourceStack.empty()) { targetStack.push(sourceStack.pop()); } // targetStack contains the reversed content of sourceStack


What are the different between stack and queue?

A stack is generally First In, Last Out, and a queue is First In First Out.Item can be added or removed only at one end in stack and in a queue insertion at the rear and deletion from the front.The basic operation of stack are 'push' and 'pop', on other hand of queue are 'enque' and 'dequeue'.