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

Scissors - Gloria V. #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Scissors - Gloria V. #44

wants to merge 4 commits into from

Conversation

ggrossvi
Copy link

@ggrossvi ggrossvi commented Jan 7, 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 of object which is described by the methods it has and how they perform. Implementation details are not included.
Describe a Stack A Stack is a data structure which stores a list of data and only provides access in a Last-In-First-Out (LIFO) order.You can use any linear structure. You can not remove from the middle or end.
What are the 5 methods in Stack and what does each do? 1. Push(item) puts an item into the stack at the top,Time O(1) 2. pop method removes and returns the item on the top of the stack. Time O(1) 3.Is_empty return true if the stack is empty and false otherwise. 4. Peek returns but does not remove the item on top of the stack and 5. Size returns the number of items on the stack
Describe a Queue A queue unlike a stack operates in a first-in-first out order. Like a line of people at a concert, the first element to enter the queue is the first element removed FIFO. Worker processes that need to be tackled in order received.
What are the 5 methods in Queue and what does each do? 1. enqueue(item) - This method puts an item into the back of the queue. You enter via the end/back. 2. dequeue - This method removes and returns the item at the front of the queue. 3.is_empty - This method returns true if the queue is empty and false otherwise. 4. Peek returns but does not remove the item on top of the stack and 5. Size returns the number of items on the stack.
What is the difference between implementing something and using something? In ADT implementation details are not included so it is abstract. The implementor knows the details of the methods but a user can use your interface and not know the details

OPTIONAL JobSimulation

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

Copy link

@CheezItMan CheezItMan 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 Gloria, you hit the learning goals here. Well done.

Comment on lines 66 to 70
def dequeue(self):
""" Removes and returns an element from the Queue
Raises a QueueEmptyException if
The Queue is empty.
The Queue is empty. In the circular Queue it remove the item at the front
"""

Choose a reason for hiding this comment

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

👍

tmp = self.store[self.front]
self.front = (self.front + 1) % INITIAL_QUEUE_SIZE
self.size -=1
return tmp

def front(self):

Choose a reason for hiding this comment

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

👍



def size(self):

Choose a reason for hiding this comment

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

👍

Comment on lines +108 to +110
if self.size == 0:
return True
return False

Choose a reason for hiding this comment

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

This is a bit simpler

Suggested change
if self.size == 0:
return True
return False
return self.size == 0

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

👍

raise StackEmptyException('We have a problem')
'''



class Stack:

Choose a reason for hiding this comment

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

👍 The stack methods look good

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