Skip to content

Conversation

alieibarra
Copy link

@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

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

🟢

@@ -15,47 +15,43 @@ def __init__(self):
self.front = -1
self.rear = -1
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.size += 1
self.rear = (self.rear+1)% self.buffer_size


def dequeue(self):

Choose a reason for hiding this comment

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

self.size -= 1
self.store[self.front] = None
self.front = (self.front +1) % self.buffer_size
return element

def front(self):

Choose a reason for hiding this comment

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

pass

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

The Queue
"""
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.


def __str__(self):
""" Returns the Queue in String form like:

Choose a reason for hiding this comment

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

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