Skip to content

Spruce - Michelle Morales#15

Open
DynamicDev3000 wants to merge 2 commits into
AdaGold:masterfrom
DynamicDev3000:master
Open

Spruce - Michelle Morales#15
DynamicDev3000 wants to merge 2 commits into
AdaGold:masterfrom
DynamicDev3000:master

Conversation

@DynamicDev3000

Copy link
Copy Markdown

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?

@kyra-patton kyra-patton left a comment

Copy link
Copy Markdown

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.

🟢

Comment thread stacks_queues/queue.py
self.size = 0


def enqueue(self, element):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread stacks_queues/queue.py
self.rear = (self.rear + 1) % self.buffer_size
self.size += 1

def dequeue(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread stacks_queues/queue.py
self.rear = -1
return value

def front(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread stacks_queues/queue.py
self.buffer_size = INITIAL_QUEUE_SIZE
self.front = -1
self.rear = -1
self.rear = 0

Copy link
Copy Markdown

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 thread stacks_queues/queue.py
Comment on lines +65 to +67
if self.front == -1:
return 0
return self.size

Copy link
Copy Markdown

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

Comment thread stacks_queues/queue.py
for x in range(size):
result.append(self.store[index])
index = (index + 1) % self.buffer_size
size -= 1

Copy link
Copy Markdown

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

Comment thread stacks_queues/stack.py
Returns None
"""
pass
self.store.add_first(element)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread stacks_queues/stack.py
returns None
"""
pass
return self.store.remove_first()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread stacks_queues/stack.py
And False otherwise
"""
pass
return self.store.empty()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread stacks_queues/stack.py
ending with the bottom of the Stack.
"""
pass
return str(self.store)

Copy link
Copy Markdown

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