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

pass all test case for queues and stack assignment #40

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

Conversation

Eatmine
Copy link

@Eatmine Eatmine commented Jun 13, 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
What are the 5 methods in Stack and what does each do? push, pop, is empty, peek, and size. Push puts an item into the stack at the top. Pop removes and returns the item on the top of the stack. Is empty returns true if the stack is empty and false otherwise. Peek return the top item in the stack. If the stack is empty, raise an exception. Size return the number of items on the stack.
|

| Describe a Queue | A queue opeerates in a first-in-first out order. The first element to enter the queue is the first el |
| What are the 5 methods in Queue and what does each do? | enqueue puts an item into the back of the queue. dequeue removes and returns the item at the front of the queue. Is_empty returns true if the queue is empty and false otherwise. Size, returns the number of the size in the queue. Front returns an element from the front of the Queue and None if the Queue is empty. |
| What is the difference between implementing something and using something? | Implementing is accomplishing or completing a task and using something means to call an API. |

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 Min. I left a few comments and suggestions, but overall nice implementation. Let me know what questions you have.

For the difference between implementing something and using something, note that 'using something' doesn't necessarily mean using an API, it just means using code that someone else implemented. You could use an API, or it could be a library, module, or function someone else implemented.

🟢

@@ -15,47 +19,95 @@ 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.



def dequeue(self):
""" Removes and returns an element from the Queue
Raises a QueueEmptyException if
The Queue is 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
if self.store[self.front]:

Choose a reason for hiding this comment

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

🤔 Since you do not reassign None as the value of whichever elements you dequeue in your dequeue implementation, this conditional may evaluate to True even when the queue is empty. I would suggest checking if your queue is empty to determine whether or not you should return the front element instead.

Suggested change
if self.store[self.front]:
if self.empty():

if self.store[self.front]:
return self.front
else:
return None


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 +87 to +90
if self.size == 0:
return True
else:
return False

Choose a reason for hiding this comment

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

Minor style suggestion to condense your code!

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

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

✨ Love the comments!

@@ -12,7 +12,10 @@ def push(self, element):
""" Adds an element to the top of the Stack.
Returns None
"""
pass

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

pass

if self.store.length() == 0:
return None

Choose a reason for hiding this comment

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

Per the specification, you want to raise a StackEmptyException here instead

if self.store.length() == 0:
return None
else:
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.

Per the specification, you don't want to return anything!

Suggested change
return self.store.remove_first()
self.store.remove_first()

return None
else:
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.

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