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

Julia Kingrey #28

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

Julia Kingrey #28

wants to merge 13 commits into from

Conversation

Kalakalot
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 a data type where the interface is specified but not the implementation. Typically the user has access to methods but implementation is a 'black box'.
Describe a Stack A stack is a "last in, first out" abstract data type typically implemented as a linked link or array. When an item is added to a stack, it goes after / on top of existing items, and when an item is removed, it's always the one that's been on the stack for the least amount of time.
What are the 5 methods in Stack and what does each do? Initialize: defines what data type stack will be implemented as (linked list in this case). Push: adds an element to the end/top of stack. Pop: Removes the element at the end/top of the stack. Empty?: returns true if the stack is empty and false otherwise. to_s: returns the linked list as a string to help test comparisons.
Describe a Queue A queue is a "first in, first out" abstract data type that's also typically implemented as a linked list or array. The first item added to an empty queue stays at the front of the list when additional items are added and is the first element to go when elements are removed.
What are the 5 methods in Queue and what does each do? Initialize: defines the queue's data structure (array in this case), instance variables needed to implement a circular buffer (front index and back index), and a default value for whether the queue is empty. Enqueue: Adds an item to the queue (to the front if the queue is empty, after the most recently added item if not). Dequeue: Removes the item at the front of the queue and returns it. Size: Returns the value used to calculate whether front or back needs to wrap around queue. Empty: Returns true if the queue is empty.
What is the difference between implementing something and using something? Implementing means writing the code. Using means using code someone else has written.

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.

Problem s with some of your minor Queue methods, but you do have enqueue and dequeue working right. Nice work.

Comment on lines +21 to +25
if hash['('] == hash[')'] && hash['{'] == hash['}'] && hash['['] == hash[']']
return true
else
return false
end

Choose a reason for hiding this comment

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

This doesn't quite work as it only counts the number of the characters, not if they're matched.

@back = -1

# default status is empty
@is_empty = true
end

def enqueue(element)

Choose a reason for hiding this comment

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

👍

if @is_empty
@is_empty = false
end

end

def dequeue

Choose a reason for hiding this comment

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

👍

end

def front
raise NotImplementedError, "Not yet implemented"
@front

Choose a reason for hiding this comment

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

Suggested change
@front
return @store[@front]

end

def size
raise NotImplementedError, "Not yet implemented"
return @store.length

Choose a reason for hiding this comment

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

This gets you the size of the internal array, not the amount of elements stored in the queue.

end

def empty?
raise NotImplementedError, "Not yet implemented"
return @is_empty
end

def to_s

Choose a reason for hiding this comment

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

Needs to be updated.

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