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

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

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

🟢



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

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


return front

def front(self):

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?

return self.store[self.front]


def size(self):

Choose a reason for hiding this comment

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

pass
return self.size

def empty(self):

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!

else:
return False

def __str__(self):

Choose a reason for hiding this comment

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

✨ Very elegant!

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.

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.

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.

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.

2 participants