Programming is like sex: one mistake and you’re providing support for a lifetime. Michael Sinz

3 stacks in One array

Language Java | Level Intermediate | Category Data structure | August 30, 2015 12:50 pm


Data structure Description

The stack is a data structure which store the element using last in first out order (LIFO). The stack can be implemented using Arrays and Linked list. The elements are interspersed between each stack. When element removed from one stack, the array should manage the gaps between the elements.

Write a program to implement three stacks in a single array. The program can use an array to store three stacks.


Output

   					 

Push to Stack 1 :12
Push to Stack 1 :48
Push to Stack 1 :86

Push to Stack 2 :45
Push to Stack 2 :23
Push to Stack 2 :34

Push to Stack 3 :9
Push to Stack 3 :67
Push to Stack 3 :22


Pop from Stack 1 : 86
Pop from Stack 1 : 48
Pop from Stack 1 : 12

Pop from Stack 2 : 34    
Pop from Stack 2 : 23
Pop from Stack 2 : 45

Pop from Stack 3 : 22
Pop from Stack 3 : 67
Pop from Stack 3 : 9

				    

Comments


No comments available!

Please login to add comments.