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

Nourhan - Spruce - C16 #50

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

Conversation

Nourhan21
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?
Describe a Stack
What are the 5 methods in Stack and what does each do?
Describe a Queue
What are the 5 methods in Queue and what does each do?
What is the difference between implementing something and using something?

OPTIONAL JobSimulation

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

@Nourhan21 Nourhan21 changed the title Nourhan - Spruce - C19 Nourhan - Spruce - C16 Jul 21, 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, Nourhan. I left some small suggestions, but overall you have a very solid and unique implementation. Let me know what questions you have.

🟢

@@ -23,39 +23,58 @@ def enqueue(self, element):
In the store are occupied
returns None
"""
pass
if self.size == 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 suggest using buffer_size over INITIAL_QUEUE_SIZE here. Imagine you alter your implementation so that the buffer_size could expand in certain cases. Then you would have to manually change all of your references to INITIAL_QUEUE_SIZE to maintain your code.

Suggested change
if self.size == INITIAL_QUEUE_SIZE:
if self.size == self.buffer_size:

Comment on lines +28 to +31
index = self.rear % self.buffer_size
self.store[index] = element
self.rear -= 1
self.size += 1

Choose a reason for hiding this comment

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

Interesting to decrease the rear pointer instead of increasing it! 😎

index = self.rear % self.buffer_size
self.store[index] = element
self.rear -= 1
self.size += 1

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.

element = self.store[index]
self.front -= 1
self.size -= 1
return element

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

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.size == 0

Choose a reason for hiding this comment

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


def __str__(self):
""" Returns the Queue in String form like:
[3, 4, 7]
Starting with the front of the Queue and
ending with the rear of the Queue.
"""
pass
result = []

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

if self.empty():
raise StackEmptyException()

return self.store.remove_last()

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):
""" Returns the Stack in String form like:
[3, 4, 7]
Starting with the top of the Stack and
ending with the bottom of the Stack.
"""

Choose a reason for hiding this comment

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

✨ This does work, but you could also take advantage of the str method in the LinkedList class

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