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

Tiffany C. #34

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Tiffany C. #34

wants to merge 3 commits into from

Conversation

TiffanyChio
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? 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

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

# Time Complexity: ?
# 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)

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.

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)
# Space Complexity: O(n)
def evaluate_postfix(postfix_expression)

Choose a reason for hiding this comment

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

👍


class Queue

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!

def initialize
@store = Array.new(30)
@front = @back = 0
# full when front == back

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!

@back = (@back + 1) % @store.length
end

def dequeue

Choose a reason for hiding this comment

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

👍

# full when front == back
end

def enqueue(element)

Choose a reason for hiding this comment

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

👍

Comment on lines +35 to +41
def front
raise NotImplementedError, "Not yet implemented"
end

def size
raise NotImplementedError, "Not yet implemented"
end

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 on lines +47 to +49
def to_s
return @store.compact.to_s
end

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