Skip to content

Jesse Pope - CS Fun Stacks and Queues#31

Open
jessepope wants to merge 1 commit intoAda-C16:masterfrom
jessepope:master
Open

Jesse Pope - CS Fun Stacks and Queues#31
jessepope wants to merge 1 commit intoAda-C16:masterfrom
jessepope:master

Conversation

@jessepope
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? ADT are a way to provide classes/methods for external use while keeping the internal mechanisms hidden.
Describe a Stack A stack is a data structure that follows a FILO pattern. The main methods are push, to add an element to the top of the stack, and pop, to remove and return an element from the top of the stack.
What are the 5 methods in Stack and what does each do? init, dunder method which initializes new store. Push, adds an element to the top. Pop, removes and returns the top element. Empty, returns boolean if stack is empty or not. str, returns data store as string.
Describe a Queue A queue is a data structure that follows the FIFO pattern
What are the 5 methods in Queue and what does each do? enqueue, adds an element to the back. dequeue, removes an element from the front. front, returns front element. size, returns size of queue. empty, returns boolean of whether or not queue is empty
What is the difference between implementing something and using something? implementing is creating the method or class for use by other people

OPTIONAL JobSimulation

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

@jessepope jessepope changed the title Complete stack and queue methods Jesse Pope - CS Fun Stacks and Queues May 28, 2022
Copy link
Copy Markdown

@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.

✨🤠 Nice work! I left a few comments regarding how we can tell if the queue is empty, but otherwise solid implementation. Let me know what questions you have.

🟢

Comment thread stacks_queues/queue.py


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.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.

✨ This is all correct, however consider the case that you remove the last element in the queue. You may want to redirect your front and rear pointers to point at -1 as an indication the queue is empty.

Comment thread stacks_queues/queue.py

return front

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.

The rear and front pointers being equal does indicate the queue is empty, however it could also be an indication the queue is full... how else might we consider the queue being empty?

Comment thread stacks_queues/queue.py
return self.store[self.front]


def size(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
pass
return self.size

def empty(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.

👀 Same thing as your front method with self.front and self.rear being equal. Consider using self.size or think about what values self.front and self.rear will both have if the queue is empty.

However, your overall logic is correct!

Comment thread stacks_queues/queue.py
else:
return False

def __str__(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.

✨ Very elegant!

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.

2 participants