Skip to content

Tanya – Pine#37

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

Tanya – Pine#37
tt-ht wants to merge 1 commit intoAda-C16:masterfrom
tt-ht:master

Conversation

@tt-ht
Copy link

@tt-ht tt-ht commented Jun 8, 2022

Stacks and Queues

Thanks for doing some brain yoga. You are now submitting this assignment!

Comprehension Questions

Question Answer
What is an ADT? Abstract Data Types do not define implementation guidance, and therefore the implementation or methods are not known by the user. Behavior is defined but not implementation.
Describe a Stack A data structure that follows a First In Last Out pattern.
What are the 5 methods in Stack and what does each do? A stack will have a push method (adds item to queue), a pop method (removes the last item added to queue), an empty method (returns boolean if stack is empty or not), a str method which returns data store as string. Dunder init method to intialize new store.
Describe a Queue A data structure that follows a First In First Out pattern.
What are the 5 methods in Queue and what does each do? A queue has a enqueue method (adds item to queue), a dequeue method (removes item from queue), and an empty method (returns boolean if queue is empty or not). It could also have a front method which returns the first value in the queue, and a size method to find the size of the queue.
What is the difference between implementing something and using something? Implementing is writing the logic and creating the methods/classes for use.

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 one comment down below. Let me know what questions you have.

🟢



def enqueue(self, element):

Choose a reason for hiding this comment

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

self.size += 1
return None

def dequeue(self):

Choose a reason for hiding this comment

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

return temp


def front(self):

Choose a reason for hiding this comment

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

return self.front


def size(self):

Choose a reason for hiding this comment

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

pass
return self.size

def empty(self):

Choose a reason for hiding this comment

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

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.

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.

pass
self.store.add_first(element)

def pop(self):

Choose a reason for hiding this comment

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

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

ending with the bottom of the Stack.
"""
pass
return self.store.__str__()

Choose a reason for hiding this comment

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

Defining the __str__ method in a class is what we call operator overloading -- Python will convert any object to a string with the str() method by default, but it may not always be what we want. By defining the __str__ method, we can overwrite Python's default behavior to behavior that we want. However, when we call the overloaded method on an instance of the class, we do not need the dunders, we can just say str(object_instance)

Suggested change
return self.store.__str__()
return str(self.store)

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