๐Ÿ“ฆ rooftopcellist / PythonDataStructures

๐Ÿ“„ LinkedQueue.py ยท 57 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57'''
Program: Linked Queue Stack
Author: Christian M. Adams

Notes: Builds a Linked Queue using the framework of LinkedList.py

'''

#Linked Stack

from LinkedList import LinkedList

class LinkedQueue:
	def __init__(self):
		self.queue = LinkedList()
	
#push(item) - adds a new item to the front of the stack
	def enqueue(self, item):
		self.queue.add(item)
	
	#pop(): item - removes and returns the last item aded.
	def dequeue(self):
		return self.queue.pop()
		
	#peek(): item - returns the item at the front of the stack, stack is unchanged
	def peek(self):
		return self.queue.peek()
		
	#isEmpty() - returns True when the stack is empty.
	def isEmpty(self):
		self.queue.isEmpty()
			
	#size() - returns the number of items in the stack.
	def size(self):
		self.queue.size()
		
	#printStack() - prints the items in the stack.	
	def printQueue(self):
		self.queue.printList("Items in Stack")
		
def main():
	myQueue = LinkedQueue()
	for i in range(10):
		myQueue.enqueue(2*i)
	myQueue.printQueue()
	
	for i in range(1,10,2):
		myQueue.dequeue()
		
	myQueue.printQueue()
		
	
	
main()