A stack is a Last In First Out (LIFO) data structure. This means that the last element inserted will be the first to be processed on the stack. Stacks work with the concepts of pushing an element on the top of the stack (PUSH) and popping an element from the top of the stack (POP).

Stacks are widely used in programming. One example of stack usage is in the functions of a programming language like C.
When a function for example DrawLine() is called from DrawSquare(), the parameters of DrawLine() are placed on the stack, followed by the return address and the local variables of DrawLine(). The StackPointer points to the top of the stack and the FramePointer is used to access the memory locations. Once DrawLine() finishes execution, it is popped off from the stack and execution starts from the return address.
The stack can be easily implemented using our implementation of the linked list. This is because a stack can be considered as a special form of a linked list which allows insertion at the head (PUSH) and deletions from the head (POP). The program has been compiled using gcc 4.4.1. There is a stack_test.c to explain the usage of the stack functions. The program can be compiled using the Makefile by issuing the “make” command on any Linux bash shell.
Download implementation of the stack
Related Posts:
Tags: programs

