Skip to content

Tiffany C.#34

Open
TiffanyChio wants to merge 3 commits into
Ada-C12:masterfrom
TiffanyChio:master
Open

Tiffany C.#34
TiffanyChio wants to merge 3 commits into
Ada-C12:masterfrom
TiffanyChio:master

Conversation

@TiffanyChio
Copy link
Copy Markdown

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? It's a wrapped class where you don't have to worry about the inner workings or implementation; just how to use it.
Describe a Stack First in, last out.
What are the 5 methods in Stack and what does each do? I only worked on 3: push, pop, and empty. Push adds an item onto the stack. Pop removes the topmost item. Empty checks if the stack is empty.
Describe a Queue First in, first out.
What are the 5 methods in Queue and what does each do? I only implemented 3: enqueue, dequeue, and empty. Enqueue adds something to the back of the queue. Dequeue removes something from the front of the queue. And empty checks if the queue is empty.
What is the difference between implementing something and using something? Implementing entails creating something. Using something is just invoking what's already in place.

OPTIONAL JobSimulation

Question Answer
Did you include a sample run of your code as a comment? I don't know what that means?

Copy link
Copy Markdown

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

Nicely done, some small issues with Queue. Take a look at my comments, but you hit all the major learning goals here.

Comment thread lib/problems.rb
# Space Complexity: ?
# Time Complexity: O(n), push and pop should be O(1) operations since the linked list has both a head and tail pointer
# Space Complexity: O(n) if the string is not balanced and comprised wholly of open brackets, also O(n) if it actually closes
def balanced(string)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works, but you can make it simpler by using a hash to do the mashing instead of using the case statement.

Comment thread lib/problems.rb
# Space Complexity: ?
# Time Complexity: O(n)
# Space Complexity: O(n)
def evaluate_postfix(postfix_expression)
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 lib/queue.rb
class Queue
require_relative './linked_list'

class Queue
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ This isn't using a circular buffer like requested!

Comment thread lib/queue2.rb
def initialize
@store = Array.new(30)
@front = @back = 0
# full when front == back
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

But when this object is created they're both equal!

Comment thread lib/queue2.rb
@back = (@back + 1) % @store.length
end

def dequeue
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 lib/queue2.rb
# full when front == back
end

def enqueue(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 lib/queue2.rb
Comment on lines +35 to +41
def front
raise NotImplementedError, "Not yet implemented"
end

def size
raise NotImplementedError, "Not yet implemented"
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So not all done

Comment thread lib/queue2.rb
Comment on lines +47 to +49
def to_s
return @store.compact.to_s
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works but it doesn't preserve element order if the back has wrapped around the buffer.

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