Stack
A stack (sometimes called a “push-down stack”) is an ordered collection of items where the addition of new items and the removal of existing items always takes place at the same end. This end is commonly referred to as the “top.” The end opposite the top is known as the “base.”
The base of the stack is significant since items stored in the stack that are closer to the base represent those that have been in the stack the longest. The most recently added item is the one that is in position to be removed first. This ordering principle is sometimes called LIFO, last-in first-out. It provides an ordering based on length of time in the collection. Newer items are near the top, while older items are near the base.
1 | def Dec_to_Bin(nums): |
1100011
100101
Queue
A queue is an ordered collection of items where the addition of new items happens at one end, called the “rear,” and the removal of existing items occurs at the other end, commonly called the “front.” As an element enters the queue it starts at the rear and makes its way toward the front, waiting until that time when it is the next element to be removed.
The most recently added item in the queue must wait at the end of the collection. The item that has been in the collection the longest is at the front. This ordering principle is sometimes called FIFO, first-in first-out. It is also known as “first-come first-served.”
1 | import random |
Average Wait 59.57 secs 0 tasks remaining.
Average Wait 65.32 secs 0 tasks remaining.
Average Wait 33.77 secs 0 tasks remaining.
Average Wait 45.81 secs 0 tasks remaining.
Average Wait 16.58 secs 0 tasks remaining.
Average Wait 46.65 secs 0 tasks remaining.
Average Wait 132.59 secs 1 tasks remaining.
Average Wait 36.56 secs 0 tasks remaining.
Average Wait 65.07 secs 0 tasks remaining.
Average Wait 66.28 secs 0 tasks remaining.
Average Wait 31.38 secs 1 tasks remaining.
Average Wait 71.24 secs 0 tasks remaining.
Average Wait 28.50 secs 0 tasks remaining.
Average Wait 29.76 secs 0 tasks remaining.
Average Wait 27.44 secs 0 tasks remaining.
Average Wait 16.71 secs 0 tasks remaining.
Average Wait 21.87 secs 0 tasks remaining.
Average Wait 36.16 secs 0 tasks remaining.
Average Wait 25.22 secs 0 tasks remaining.
Average Wait 69.79 secs 0 tasks remaining.