It is a type of data structure which conatins a bunch of nodes, where these nodes hve a reference from each other.
- Push node or item that are added to the last of the stack list.
- Pop removes of the last node or item in the stack.
- Top the last node or item within the stack.
- Peek to view the value of top or last node of the stack.
Check out the folowing figure to understand the stack how it looks like and the terminology that we've mentioned them before.
-
FILO stand for first in last out, which means the item that you are going to add it, will be the last node popped out of the stack.
-
LIFO stand for last in first out, which means the item that you are going to add lately it, will be the first node popped out of the stack.
It is a simple process that you only need to push the new node and assign it as a top of the stack, then the you assign the next node as the original top. The same process would go with the pop.
- Enqueue node or item that is added to the queue.
- Dequeue node or item that is removed from the queue.
- Front the first node or item in the queue.
- Rear the last node or item in the queue.
- Peek to view the value of front or first node in the queue.
- IsEmpty to check if the queue is empty or not.
By understanding the terminologies above, you will be then familiar on how the queue will look like as the following figure.
- FIFO stand for first in first out, which the first node that are added will be the first one will pop out of the queue.
- LILO stand for last in last out, which the last node in the queue will be the last node will pop out of the queue.
The idea would be changing the net value of first node to be pointed out to the added node which is by using the method rear. Then, reassign the rear into the added node and make it next value to the null.