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

Spruce - Michelle Morales #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

DynamicDev3000
Copy link

Stacks and Queues

Thanks for doing some brain yoga. You are now submitting this assignment!

Comprehension Questions

Question Answer
What is an ADT?
Describe a Stack
What are the 5 methods in Stack and what does each do?
Describe a Queue
What are the 5 methods in Queue and what does each do?
What is the difference between implementing something and using something?

OPTIONAL JobSimulation

Question Answer
Did you include a sample run of your code as a comment?

Copy link

@kyra-patton kyra-patton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤠💫 Very solid implementation, Michelle! Make sure you fork against the C16 version instead of AdaGold next time! Let me know what questions you have.

🟢

self.size = 0


def enqueue(self, element):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


self.store[self.rear] = element
self.rear = (self.rear + 1) % self.buffer_size
self.size += 1

def dequeue(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if self.front == self.rear:
self.front = -1
self.rear = -1
return value

def front(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -13,49 +13,78 @@ def __init__(self):
self.store = [None] * INITIAL_QUEUE_SIZE
self.buffer_size = INITIAL_QUEUE_SIZE
self.front = -1
self.rear = -1
self.rear = 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's not really anything wrong with initializing this to 0, but since you reset it to '-1' in dequeue below when the queue becomes empty, it's best to stay consistent across the board.

Suggested change
self.rear = 0
self.rear = -1

Comment on lines +65 to +67
if self.front == -1:
return 0
return self.size

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since size should already be 0 if the queue is empty, you can probably delete lines 65 - 66.

Suggested change
if self.front == -1:
return 0
return self.size
return self.size

for x in range(size):
result.append(self.store[index])
index = (index + 1) % self.buffer_size
size -= 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally try not to change the value we are iterating through, and it's not necessary to modify size here.

Suggested change
size -= 1

@@ -12,7 +12,7 @@ def push(self, element):
""" Adds an element to the top of the Stack.
Returns None
"""
pass
self.store.add_first(element)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -21,18 +21,18 @@ def pop(self):
The Stack is empty.
returns None
"""
pass
return self.store.remove_first()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def empty(self):
""" Returns True if the Stack is empty
And False otherwise
"""
pass
return self.store.empty()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def __str__(self):
""" 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
return str(self.store)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Successfully merging this pull request may close these issues.

3 participants