Skip to content

Time - Alicia#36

Open
aecombs wants to merge 9 commits intoAda-C13:masterfrom
aecombs:master
Open

Time - Alicia#36
aecombs wants to merge 9 commits intoAda-C13:masterfrom
aecombs:master

Conversation

@aecombs
Copy link

@aecombs aecombs commented Sep 15, 2020

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? Stands for abstract data type — it's a type of class that holds data and works behind the scenes to take care of the specifics of how it stores data while allowing the user to use simple methods to alter its state
Describe a Stack A type of ADT that stores its data such that the data is stacked onto itself. The first piece of data will remain on the bottom of the stack and the pop method takes from the top.
What are the 5 methods in Stack and what does each do? Push - adds data to the top; pop - removes data from the top; empty? - checks if there's data currently stored in the stack; size - returns the number of elements in the stack; initialize - instantiates an empty stack
Describe a Queue A type of ADT that stores its data such that the data goes in and comes out in the order that it was put in — push will add to the end of the structure and pop will take from the beginning.
What are the 5 methods in Queue and what does each do? Enqueue - adds to the end of the queue; dequeue - takes away from the beginning of the queue; first - returns information about what's stored at the beginning of the queue; size - returns the number of elements in the queue; empty? - checks whether there is data currently stored in the queue; to_s - returns a stringified array of the elements in the queue in the order that they were put in (useful for circular queues)
What is the difference between implementing something and using something? Implementing is designing and writing out the object you intend to use in the future. Using is importing the object and using it without troubling yourself with the specifics on how that object manages itself.

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 Alicia, you hit the main learning goals here. Well done.

Comment on lines +9 to +10
left_half = ["(", "[", "{"]
right_half = [")", "]", "}"]

Choose a reason for hiding this comment

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

Did you know, you could also make a hash where the keys are the open parens and the values are the close parens. That way you wouldn't have to check the indexes like you are.

@last = 0
end

def enqueue(element)

Choose a reason for hiding this comment

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

👍

@last = (@last + 1) % @size
end

def dequeue

Choose a reason for hiding this comment

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

👍

Comment on lines 29 to 31
def size
raise NotImplementedError, "Not yet implemented"
return @size
end

Choose a reason for hiding this comment

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

Size usually references the number of items in the Queue.

@@ -1,19 +1,21 @@
require_relative './linked_list.rb'

class Stack

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