Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Citlalli Z- Cedar #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Citlalli Z- Cedar #33

wants to merge 1 commit into from

Conversation

MiffyBruna
Copy link

@MiffyBruna MiffyBruna commented May 30, 2022

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of values and a set of operations.
Describe a Stack A stack is a linear data structure that follows the principle of Last-In First-Out .This means the last element inserted inside the stack is removed first.
What are the 5 methods in Stack and what does each do? push: This method puts an item into the stack at the top, pop: This method removes and returns the item on the top of the stack, is_empty: This method returns true if the stack is empty and false otherwise, peek: method which returns, but does not remove the item on top of the stack, size: which would return the number of items on the stack.
Describe a Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data "enqueue" and the other is used to remove data "dequeue".
What are the 5 methods in Queue and what does each do? enqueue(item) : This method puts an item into the back of the queue, dequeue : This method removes and returns the item at the front of the queue, is_empty: This method returns true if the queue is empty and false otherwise, peek: returns the element at the front the container. It does not deletes the element in the container, length: which would return the length of the queue
What is the difference between implementing something and using something? Implementing means to put into practice while using is just utilizing a tool

OPTIONAL JobSimulation

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

@MiffyBruna MiffyBruna changed the title All tests pass Citlalli Z- Cedar May 30, 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 Citlalli! I left just one suggestion down below. Let me know what questions you have.

🟢

@@ -15,47 +16,82 @@ 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.

Comment on lines +44 to +46
if self.size == 0:
self.front = -1
self.rear = -1

Choose a reason for hiding this comment

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

I would recommend moving this to after line 52. If the queue is empty to start, it should be caught by your if statement on line 41. However, it may be the case that after dequeueing an element, your queue is now empty and you want to reset the front and rear pointers.


self.store[self.rear] = element
self.rear = (self.rear + 1) % self.buffer_size
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.

✨ Nice work! Just have one suggestion below ⬇️

self.front = (self.front + 1) % self.buffer_size
self.size -= 1

return front_item

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.front == -1:
raise QueueEmptyException("Queue is 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
self.store.add_first(element)
return None

Choose a reason for hiding this comment

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

Functions return None by default. If we aren't returning any other values, we usually prefer to let the function to implicitly return None

Suggested change
return None

@@ -9,30 +9,19 @@ def __init__(self):
self.store = LinkedList()

def push(self, element):

Choose a reason for hiding this comment

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

"""
pass
self.store.add_first(element)
return None

def pop(self):

Choose a reason for hiding this comment

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

pass
if self.store.empty():
raise StackEmptyException("Stack is empty.")
return self.store.remove_first()

def empty(self):

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()

def __str__(self):

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