Stack and Implementing Stack using Array
Introduce to stack data structure
Stack is a data structure which works based on principle of last in first out (LIFO). In computing world, stack data structure can be applied in many applications such as parsing syntax of expressions, run-time memory management (used in Java virutal machine) and solving search problem.
Stack operations
Push and pop are the operations that are provided for insertion of an element into the stack and the removal of an element from the stack.
Array Implementation of a Stack using C
Here is source code of c which demonstrate stack data structure. You can also download them to your local PC and start practicing.
Stack.h
1 | void push( int *s, int * top, int element); |
2 | int pop( int *s, int *top); |
3 | int full( int *top, const int size); |
Stack.c
13 | void push( int *s, int * top, int element) |
15 | s[(*top)++] = element; |
21 | int pop( int *s, int *top) |
29 | int full( int *top, const int size) |
31 | return *top == size ? 1 : 0; |
39 | return *top == 0 ? 1 : 0; |
Không có nhận xét nào:
Đăng nhận xét