-
Notifications
You must be signed in to change notification settings - Fork 63
Citlalli Z- Cedar #33
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from stacks_queues.linked_list import LinkedList | ||
|
||
INITIAL_QUEUE_SIZE = 20 | ||
|
||
|
@@ -15,47 +16,82 @@ def __init__(self): | |
self.front = -1 | ||
self.rear = -1 | ||
self.size = 0 | ||
|
||
|
||
def enqueue(self, element): | ||
""" Adds an element to the Queue | ||
Raises a QueueFullException if all elements | ||
In the store are occupied | ||
returns None | ||
""" | ||
pass | ||
if self.front == -1 & self.rear == -1: | ||
self.front = 0 | ||
self.rear = 0 | ||
elif self.rear == self.front: | ||
raise QueueFullException(f"Queue is full.") | ||
|
||
self.store[self.rear] = element | ||
self.rear = (self.rear + 1) % self.buffer_size | ||
self.size += 1 | ||
|
||
def dequeue(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ Nice work! Just have one suggestion below ⬇️ |
||
""" Removes and returns an element from the Queue | ||
Raises a QueueEmptyException if | ||
The Queue is empty. | ||
""" | ||
pass | ||
if self.rear == -1 and self.front == -1: | ||
raise QueueEmptyException("Queue is empty.") | ||
|
||
if self.size == 0: | ||
self.front = -1 | ||
self.rear = -1 | ||
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend moving this to after line 52. If the queue is empty to start, it should be caught by your if statement on line 41. However, it may be the case that after dequeueing an element, your queue is now empty and you want to reset the |
||
|
||
front_item = self.store[self.front] | ||
self.store[self.front] = None | ||
|
||
self.front = (self.front + 1) % self.buffer_size | ||
self.size -= 1 | ||
|
||
return front_item | ||
|
||
def front(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
""" Returns an element from the front | ||
of the Queue and None if the Queue | ||
is empty. Does not remove anything. | ||
""" | ||
pass | ||
if self.front == -1: | ||
raise QueueEmptyException("Queue is empty") | ||
return self.store[self.front] | ||
|
||
|
||
def size(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
""" Returns the number of elements in | ||
The Queue | ||
""" | ||
pass | ||
return self.size | ||
|
||
def empty(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
""" Returns True if the Queue is empty | ||
And False otherwise. | ||
""" | ||
pass | ||
return self.size == 0 | ||
|
||
def __str__(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
""" Returns the Queue in String form like: | ||
[3, 4, 7] | ||
Starting with the front of the Queue and | ||
ending with the rear of the Queue. | ||
""" | ||
pass | ||
list = [] | ||
current_item = self.front | ||
count = 0 | ||
|
||
if self.size == 0: | ||
return str(list) | ||
while count < self.size: | ||
list.append((str(self.store[current_item])).replace("'", "")) | ||
current_item =(current_item+1) % self.buffer_size | ||
count +=1 | ||
return str(list).replace("'", "") | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -9,30 +9,19 @@ def __init__(self): | |||
self.store = LinkedList() | ||||
|
||||
def push(self, element): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||||
""" Adds an element to the top of the Stack. | ||||
Returns None | ||||
""" | ||||
pass | ||||
self.store.add_first(element) | ||||
return None | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functions return
Suggested change
|
||||
|
||||
def pop(self): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||||
""" Removes an element from the top | ||||
Of the Stack | ||||
Raises a StackEmptyException if | ||||
The Stack is empty. | ||||
returns None | ||||
""" | ||||
pass | ||||
if self.store.empty(): | ||||
raise StackEmptyException("Stack is empty.") | ||||
return self.store.remove_first() | ||||
|
||||
def empty(self): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||||
""" Returns True if the Stack is empty | ||||
And False otherwise | ||||
""" | ||||
pass | ||||
return self.store.empty() | ||||
|
||||
def __str__(self): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||||
""" Returns the Stack in String form like: | ||||
[3, 4, 7] | ||||
Starting with the top of the Stack and | ||||
ending with the bottom of the Stack. | ||||
""" | ||||
pass | ||||
if self: | ||||
return str(self.store) | ||||
return "" | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨