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

Roza-Cedar, re-submission including comprehension questions #38

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

Conversation

haset-19
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? is a type of object which is described by the methods it has and how they perform. Implementation details are not included
Describe a Stack Is a data structure that stores lists of data but those data can be accessed through last in-first out
What are the 5 methods in Stack and what does each do? size, to return the total elements in a stack, is_empty to check if the stack is empty, pop to remove and return the element on top of the stack, push to insert element on the top, peek, to return top element but not doesn't remove
Describe a Queue is an abstract data structure to store a list of elements like stack but allows access only in first come first out
What are the 5 methods in Queue and what does each do? enqueue to add element at the end, dequeue to remove element from the front, is_empty, to check if the queue is empty, size to calculate the total elements and return
What is the difference between implementing something and using something? Implementing something the way the implementer prefers and abstracting the details, the data structures used etc, and the user doesn't have to know the details.

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.

✨💫 Nice work! I left a couple of suggestions. Great job on the comprehension questions. Let me know what questions you have.

🟢

@@ -23,39 +27,68 @@ def enqueue(self, element):
In the store are occupied
returns None
"""
pass
if self.size == self.buffer_size:

Choose a reason for hiding this comment

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


def dequeue(self):
""" Removes and returns an element from the Queue
Raises a QueueEmptyException if
The Queue is empty.
"""
pass
if self.empty():

Choose a reason for hiding this comment

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


def front(self):
""" Returns an element from the front
of the Queue and None if the Queue
is empty. Does not remove anything.
"""
pass
return self.store[self.front]

Choose a reason for hiding this comment

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



def size(self):
""" Returns the number of elements in
The Queue
"""
pass
return self.size

Choose a reason for hiding this comment

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


def empty(self):
""" Returns True if the Queue is empty
And False otherwise.
"""
pass
return self.front == self.rear

Choose a reason for hiding this comment

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

👀 This will check if the queue is empty, but it could also mean the queue

Comment on lines +86 to +88
while (start_index % INITIAL_QUEUE_SIZE) < INITIAL_QUEUE_SIZE and len(queue_list) < self.size:
if self.store[start_index % INITIAL_QUEUE_SIZE] is not None:
queue_list.append(self.store[start_index % INITIAL_QUEUE_SIZE])

Choose a reason for hiding this comment

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

I would recommend using self.buffer_size instead of the constants for style reasons. It will also allow us to expand our queue functionality in the future, say if we wanted to increase buffer_size instead of just raising an error.

Suggested change
while (start_index % INITIAL_QUEUE_SIZE) < INITIAL_QUEUE_SIZE and len(queue_list) < self.size:
if self.store[start_index % INITIAL_QUEUE_SIZE] is not None:
queue_list.append(self.store[start_index % INITIAL_QUEUE_SIZE])
while (start_index % self.buffer_size) < self.buffer_size and len(queue_list) < self.size:
if self.store[start_index % self.buffer_size] is not None:
queue_list.append(self.store[start_index % self.buffer_size])

@@ -12,27 +12,35 @@ def push(self, element):
""" Adds an element to the top of the Stack.
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.

def pop(self):
""" Removes an element from the top
Of the Stack
Raises a StackEmptyException if
The Stack is empty.
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.


def empty(self):
""" Returns True if the Stack is empty
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.


def empty(self):
""" Returns True if the Stack is empty
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.

✨ This works, but you might also consider taking advantage of LinkedList's str() method

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