Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

09_queue/circular_queue.py code of enqueue has bug #480

Open
1lily opened this issue Jul 8, 2020 · 0 comments
Open

09_queue/circular_queue.py code of enqueue has bug #480

1lily opened this issue Jul 8, 2020 · 0 comments

Comments

@1lily
Copy link

1lily commented Jul 8, 2020

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]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant