loading
main.py
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
class Node:
  def __init__(self, data):
    self.data = data
    self.nextNode = None

class Queue:
  def __init__(self):
    self.first = None
    self.last = None
  
  def enQueue(self, data):
    if not self.first:
      self.first = Node(data)
      self.last = self.first
      return
    self.last.nextNode = Node(data)
    self.last = self.last.nextNode

  def deQueue(self):
    temp = self.first
    self.first = self.first.nextNode
    return temp
  
  def printQueue(self):
    temp = self.first
    while temp:
      print(temp.data)
      temp = temp.nextNode

print("Creating empty queue...")
myQ = Queue()
print()

print("Creating two variables containing data...")
firstNode = 15
secondNode = 20
print()

print("Adding two nodes to the queue...")
myQ.enQueue(firstNode)
myQ.enQueue(secondNode)
print()

print("Verifying that the nodes were enQueued...")
myQ.printQueue()
print()

print("Testing the deQueue function...")
deQueuedNode = myQ.deQueue()
myQ.printQueue()
print()

print("Making sure the deQueue returned the node...")
print("...and adding deQueued node back in...")
myQ.enQueue(deQueuedNode.data)
myQ.printQueue()