Stacks & Queues

Both types of data structures (ways of holding data in computer memory) like arrays. An array is a static data structure meaning its size is always know in advance.

When variables are used to point to different elements in arrays, they can become dynamic.

Stacks and Queues are dynamic data structures. This means there size can change as they are being used.


Stacks

Stacks are Last In First Out (LIFO) data structures. This means that the most recent piece of data to be placed on to the stack is the first piece to be taken off it. Adding data to the stack is called Pushing and taking data off the stack is called Popping.

They can be difficult to implement. A pointer is used to keep track of the top of the stack. The pointer is incremented when more data is pushed and decreased when popped.


Queues

Queues are First In First Out (FIFO) data structures. This means that the most recent piece of data to be placed in the queue is the last piece taken out.

Queues are usually implemented using an array and two variables, one points to the first item (head pointer) in the queue the other to the next free space (tail pointer).

Comments

Popular posts from this blog

CPU Fetch-Decode-Execute Cycle

OSI Network Model

Scheduling