Queue: Difference between revisions
Mr. MacKenty (talk | contribs) No edit summary |
Mr. MacKenty (talk | contribs) |
||
Line 48: | Line 48: | ||
return | return | ||
def | def peek(element): | ||
# do stuff here | # do stuff here |
Revision as of 14:05, 5 December 2017
In computer science, a queue is a particular kind of abstract data type or collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position, known as enqueue, and removal of entities from the front terminal position, known as dequeue. This makes the queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that once a new element is added, all elements that were added before have to be removed before the new element can be removed. Often a peek or front operation is also entered, returning the value of the front element without dequeuing it. A queue is an example of a linear data structure, or more abstractly a sequential collection.[2]
Image of a queue[edit]
Access methods of a queue[edit]
- enqueue
- dequeue
- isEmpty
- peek
Practical applications of queue's[edit]
- Printer queues
- Computer modelling of physical queues (like in a supermarket)
Queue - video example[edit]
This video provides a basic introduction to queues
Priority Queue[edit]
In computer science, a priority queue is an abstract data type which is like a regular queue or stack data structure, but where additionally each element has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority. If two elements have the same priority, they are served according to their order in the queue.[4].
A python learning activity[edit]
Using the python list data structure, implement 4 queue functions, enqueue, dequeue, peek and isEmpty. We assume we know the name of the queue.
myQueue = []
def enqueue(element):
# do stuff here
return
def dequeue(element):
# do stuff here
return
def peek(element):
# do stuff here
return
def isEmpty(stackName):
# this function should return as boolean True or False
return
# for extra challenge create a priority queue.
Standards[edit]
- Describe the characteristics and applications of a queue.
- Construct algorithms using the access methods of a queue.
- Explain the use of arrays as static stacks and queues.
See Also[edit]
References[edit]
- ↑ http://www.flaticon.com/
- ↑ https://en.wikipedia.org/wiki/Queue_(abstract_data_type)
- ↑ This Image was created by User:Vegpuff.If you are using the image under the creative commons share alike license please credit the photo Vegpuff/Wikipedia and include a link to this page. No explicit permission is needed from me, but an email if my work has been of help to you.If you dont want to release your work under a creative commons license, please mail me at vegpuff@gmail.com or catch me at my twitter stream for a custom license. - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=7586271
- ↑ https://en.wikipedia.org/wiki/Priority_queue