repl.it
@MerlinKnight/

queues question 2

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
class CircularQeuee:

  def init(self):
    self.queue = list()
    self.head = 0
    self.tail = 0
    self.maxSize = 8

  def enqueue(seld,data):
    if self.size() == self.maxSize - 1:
      return("Queue Full!")
    self.queue.append(data)
    self.tail = (self.tail+1) % self.maxSize
    return True

  def dequeue(self):
    if self.size() == 0:
      return("Queue Empty!")
    data = self.queue[self.head]
    self.head = (self.head+1) % self.maxSize
    return data
  
  def size(self):
    if self.tail >= self.head:
      return(self.tail - self.head)
    return (self.maxSize - (self.head - self.tail))
Fetching token
?