Monday 20 December 2010

algorithm to implement stack operations by using the pointers.

Description:


In this program we have to implement the stack operation by using the pointers. Here they stack operation are push and pop. Push operation is used to insert the elements into a stack and pop operation is used to remove the elements in to a stack.



Algorithm:


Step 1: Start
Step 2: Declare the structure for the stack pointers. Step 3: Define the push function
Step 4: Define the pop function Step step 5: Define the display function Step 6: Read the choice

Step 7: if choice = push
Create a cell for the TOP cell in the stack. Place the date in the TOP cell
Place the TOP pointer to the new cell Step 8: if choice=pop
Check if empty stack. If so, print stack is empty. Otherwise, remove the TOP cell.
Step 9: if choice=display
Display all the elements in the Stack.

Step 10: Stop

VIVA QUESTIONS: 

1) Define Stack ?
Ans: A stack is a linear data structure in which a data item is inserted and deleted at one end

2) Define data structure ?
Ans: A data structure is a collection of organized data that are related to each other


3) What are the various operation performed on the stack ? Ans: push(), pop()


Program in c++




No comments:

Post a Comment