#480·algo

09_queue/circular_queue.py code of enqueue has bug

Author: 1lilyCreated Jul 8, 2020Updated Apr 22, 2026

the enqueue part is enlarge the array and didn't change it ,when the test case large, and go into tail < head, will have bugs. so need change the enqueue function as bellow: def enqueue(self,data): if (self._tail+1) % self._capacity == self._head: return False #self._value.append(data) self._tail = (self._tail+1) % self._capacity

    if len(self._value) < self._capacity -1:
        self._value.append(data)
    else:
        self._value[self._tail] = data

And also need change repr fuction as bellow: def repr(self): if self._tail >= self._head: return " ".join(item for item in self._value[self._head:self._tail]) else: return " ".join(item for item in chain(self._value[self._head:], self._value[:self._tail+1]))