Site hosted by Angelfire.com: Build your free website today!

 

Stacks (using array)

by Vangelis Livadiotis

 

A stack is a data structure that works on the Last In First Out (LIFO) principle consider a stack of plates where plates are added or taken only from the top.
Access for inserting (pushing) or removing (popping) is from the stack top (position of top plate).
The next free location on the stack is indicated by the stack top.

Instructions:

Brief Greek history: In Greece a traditional way of leisure is going to places playing live Greek music called mpouzoukia. Mpouzouki is a Greek instrument similar to a guitar. In this place it is also common to get large stacks of plates and breaking them on the stage. 

The above history was given to explain the following applet. Suppose you are at mpouzoukia and when you "push" a waiter brings more plates for you to break. He always places them on top of the previous stack (if any). The plates can write anything you want on them. When you "pop", you throw the plates starting from the last one added to your stack. Since the stack implemented here uses arrays and not pointers there is a limit to the number of plates you can have at one time. For this specific example the limit is 13. The textbox on the bottom left will provide extra information. The counting of the plates is just for fun, see how much you can break! 

For the full array stack Pascal code click here.

The stack is initialized when the page is loaded so do check the code textbox before creating a stack.

 

Home | Arrays | Arrays2 | Queues1 | Queues2 | Stacks | Arguments | Pointers |

Binary Search Tree

* Code taken from Lecture 2 in Data Structures Semester 2 2005 by Mr. Chris Cox for Oxford Brookes University.

** Music clip taken from Giannis Poulopoulos's song "To agalma"