repl.it
Python

No description

fork
loading
Files
  • main.py
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
57
58
59
60
#Define queue
class queue:
  def __init__(self, maxsize):
    self.maxsize = maxsize
    self.array = []
    for i in range(maxsize): #Creates the array
      self.array.append("")
    self.size = 0
    self.start = 0
    self.end = 0
    
  #Check if empty
  def isempty(self):
    if self.size == 0:
      return True
    else:
      return False

  #Check if full
  def isfull(self):
    if self.size == self.maxsize:
      return True
    else:
      return False
  
  #Add to the end of the queue
  def enqueue(self, item):
    if not self.isfull():
      self.array[self.end] = item
      self.end += 1
      self.size += 1
    else:
      print("/nI regret to inform that the queue is full.")

  #Remove from the start of the queue
  def dequeue(self, item):
    if not self.isempty():
      print("\nRemoving", self.array[self.start], "from the queue.")
      self.array[self.start] = ("")
      self.start -= 1
      self.size -= 1
      if self.size != 0:
        self.start += 1
    else:
      print("\nI regret to inform that the queue is empty.")

  #Display queue
  def display(self):
    for obj in self.array:
      print(obj)
      
myq = queue(6)
myq.enqueue("Riesssss")
myq.enqueue("Ruscc")
myq.enqueue("iDoc")
myq.enqueue("Jeffe")
myq.enqueue("DylMan")
myq.enqueue("Feegs")
myq.dequeue("")
myq.display()
Fetching token
?