Stack Queue
Stack Queue
Topics to be covered :
top
5 5
4 Push(41) 4 41
3 21 3 21
2 12 2 12
1 5 1 5
5 5
4 41 x = Pop() 4
3 21 3 21
2 12 2 12
1 5 1 5
Definition:
- An Abstract Data Type is some sort of data together
with a set of functions (interface) that operate on the data.
stack.h
Only defines the interface!
Data Structures and Algorithms 9
Using the Stack ADT
#include "stack.h"
void main()
{
Stack st1, st2; // declare 2 stack variables
Example: 7 1 3 + - 4 *
Stack
STACKS SKCATS
- Simply push each letter onto the stack, then pop them
back off again and hey presto!
STACKS SKCATS
21 55 7 12
Rear Front
Join(36); 36 21 55 7 12
Rear Front
Elements can only be added to the rear of the queue and removed
from the front of the queue.
36 21 55 7 12
Rear Front
Leave(); 36 21 55 7
Rear Front
[1] e2
[n-2]
e1
[0] [n-1]
front
next process
Process D C B A
Queue running
process
next process
D C B A
running
Process
process
Queue
A D C B
struct Queue
{
int items[QSIZE];
int rear;
int front;
};