Skip to content

Alie Ibarra C16#45

Open
alieibarra wants to merge 2 commits intoAda-C16:masterfrom
alieibarra:master
Open

Alie Ibarra C16#45
alieibarra wants to merge 2 commits intoAda-C16:masterfrom
alieibarra:master

Conversation

@alieibarra
Copy link
Copy Markdown

@alieibarra alieibarra commented Jul 1, 2022

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? An Abstract Data Type is a type/class where its behavior is defined by it's methods and values
Describe a Stack A Stack is an abstract data structure where the last element put in is the first element popped out (LIFO)
What are the 5 methods in Stack and what does each do? push adds an element to the top of the stack, pop removes and returns an element, is_empty will return a boolean depending on whether the stack is empty or not, peek will return the value of the top item but won't remove it, and size will return the number of items in the stack
Describe a Queue A Queue is an abstract data structure where the first element put in is the first element popped out (FIFO)
What are the 5 methods in Queue and what does each do? enqueue adds an element to back of the queue, dequeue removes and returns the element at the front of the queue, is_empty will return a boolean depending on whether the stack is empty or not, front will return the element from the front item but won't remove it from the queue, and size will return the number of items in the queue
What is the difference between implementing something and using something? Methods must first be implemented (created) in order to use them

OPTIONAL JobSimulation

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

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.

✨🌸 Very clean implementation Alie! 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


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.front = (self.front +1) % self.buffer_size
return element

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
if self.size > 0:
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.

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

def __str__(self):
""" Returns the Queue in String form like:
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
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