Skip to content

pass all test case for queues and stack assignment#40

Open
Eatmine wants to merge 1 commit intoAda-C16:masterfrom
Eatmine:master
Open

pass all test case for queues and stack assignment#40
Eatmine wants to merge 1 commit intoAda-C16:masterfrom
Eatmine:master

Conversation

@Eatmine
Copy link
Copy Markdown

@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
Copy Markdown

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

🟢

Comment thread stacks_queues/queue.py


def enqueue(self, element):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread stacks_queues/queue.py
def dequeue(self):
""" Removes and returns an element from the Queue
Raises a QueueEmptyException if
The Queue is empty.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread stacks_queues/queue.py
is empty. Does not remove anything.
"""
pass
if self.store[self.front]:
Copy link
Copy Markdown

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

Comment thread stacks_queues/queue.py
return None


def size(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread stacks_queues/queue.py
Comment on lines +87 to +90
if self.size == 0:
return True
else:
return False
Copy link
Copy Markdown

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

Comment thread stacks_queues/queue.py
else:
return False

def __str__(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✨ Love the comments!

Comment thread stacks_queues/stack.py
"""
pass

return self.store.add_first(element)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread stacks_queues/stack.py
pass

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

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

Comment thread stacks_queues/stack.py
if self.store.length() == 0:
return None
else:
return self.store.remove_first()
Copy link
Copy Markdown

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

Comment thread stacks_queues/stack.py
return self.store.remove_first()


def empty(self):
Copy link
Copy Markdown

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