Skip to content

Ports - Jillianne#30

Open
jillirami wants to merge 10 commits intoAda-C11:masterfrom
jillirami:master
Open

Ports - Jillianne#30
jillirami wants to merge 10 commits intoAda-C11:masterfrom
jillirami:master

Conversation

@jillirami
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? An Abstract data type is an object that is understood through the methods they have and actions those take.
Describe a Stack Data type that stores a list of data and provides access by last in, first out.
What are the 5 methods in Stack and what does each do? Push - add value to top of stack. Pop - returns and removes value at top of stack. Is_empty - returns true or false if stack is empty or not. Peek - returns value of item at top of stack but does not remove the item. Size - returning the amount of items on the stack.
Describe a Queue Data type that stores a list of data and provides access by first in, first out.
What are the 5 methods in Queue and what does each do? Enqueue - add value to front of queue. Dequeue - remove and return value from the front of queue. Front - return value at front of queue, but does not remove. Size - return numerical size of queue. Empty? - return true or false if queue empty or not.
What is the difference between implementing something and using something? An implementation is to carry out the method of something, whereas using something is explicitly demonstrating the internal workings of what is being used.

OPTIONAL JobSimulation

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

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.

Overall nice work, some small bits could use some work. Take a look at my comments and let me know if you have questions.

Comment on lines +4 to +28
string_stack = Stack.new()
length = 0

string.each_char do |char|
string_stack.push(Node.new(char))
length += 1
end

return false if length % 2 != 0

length /= 2
comparison_string_stack = Stack.new()

length.times do
comparison_string_stack.push(string_stack.pop)
end

key = {"[" => "]", "]" => "[", "{" => "}", "}" => "{", "(" => ")", ")" => "("}

until string_stack.empty?
letter1 = string_stack.pop
letter2 = comparison_string_stack.pop
return false if letter1.data != key[letter2.data]
end
return true

Choose a reason for hiding this comment

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

This method wouldn't work for this balanced string
"{()}[()]"

Consider just using one stack, and traverse the string. When you see a start brace of some sort, you push it on the stack, when you see a close brace you pop and see if they match.

By the end the stack should be empty.

dequeued = @store[@front]
@store[@front] = nil

self.size == 0 ? @front = @rear = -1 : @front = (@front + 1) % QUEUE_SIZE

Choose a reason for hiding this comment

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

I would say if self.size == 1 (because you'd have 1 element).


def size
raise NotImplementedError, "Not yet implemented"
store = @store.select { |item| item != nil }

Choose a reason for hiding this comment

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

You could also do this in O(1) with some math.

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