[Tutor] confused by linked queue
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Wed Jul 26 00:43:34 CEST 2006
> One of my problems in conecptualizing this is that I thought a linked
> queue was just a linked list. Is a linked queue a linked list? There
> seems to be a subtle difference...
Hi Chris,
I think you mean to ask:
Is a "queue" a linked list?
Here's another particular possible queue class that does something
similar, but with Python's regular lists rather than a linked list:
######################################
class ArrayQueue:
def __init__(self):
self.elements = []
def isEmpty(self):
return len(self.elements) == 0
def insert(self, elt):
self.elements.append(elt)
def remove(self):
return self.elements.pop(0)
######################################
This works on a different principle than the linked list queue, but it
does the same stuff. The main idea is that a "queue" can be anything, as
long as it supports three operations:
* isEmpty
* insert
* remove
That is, a queue is an abstract concept, and the LinkedQueue and
ArrayQueue classes are particular, concrete implementations of that
abstract concept.
A mechanic is someone who's good with their hands. MacGyver is a
particular, concrete mechanic who knows how to blow things up with
toothpaste. MacGyver is an implementation of a mechanic.
A "car vehicle" is an abstract concept; a Camry is a particular, concrete
car that anyone can look at and agree is a car. We can also look at a
Prius and also agree that this is a car, even though the engine underneath
the hood might look weird.
I hope this is making some sort of sense. *grin*
More information about the Tutor
mailing list