-
Notifications
You must be signed in to change notification settings - Fork 42
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
Lynn Griffin - Edge : passed all test; created helper function for postfix_expression logic #20
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some confusion here on the circular buffer and using a linked list for the stack. Otherwise not bad. Take a look at my comments and let me know if you have any questions. It was good seeing you on Saturday!
end | ||
|
||
s = Stack.new(string.length) | ||
validator = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good use of a hash!
end | ||
end | ||
|
||
def arithmetic(first_num, second_num, exp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice helper method!
end | ||
|
||
def enqueue(element) | ||
raise NotImplementedError, "Not yet implemented" | ||
if @back == @front - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a little bit more math here, because the back can wrap around the array. This isn't quite right.
print "full" | ||
else | ||
@ari[@back] = element | ||
@back += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the back can wrap around the array this should be @back = (@back + 1) % QUEUE_SIZE
print "empty" | ||
end | ||
removed = @ari[@front] | ||
@front += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the above you have to handle the situation where front goes past the end of the array: @front = (@front + 1) % QUEUE_SIZE
Also you should check to see if the queue is now empty.
attr_accessor :store, :size | ||
|
||
def initialize(length) | ||
@store = Array.new(length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stack was supposed to use a linked list.
s.push(2) | ||
s.push(3) | ||
s.to_s.must_equal "[1, 2, 3]" | ||
s.push(4).must_equal "Stack Overflow" #change this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe raise an exception in this circumstance.
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
|
| Describe a Stack | a data structure similar to an array utilizing LIFO (last in, first out) methods to add, access, and remove elements.
|
| What are the 5 methods in Stack and what does each do? |
push => add elements to top of stack; insert at first index and populates array
pop => remove elements from top of stack; remove element at last index in array
peek => prints the element at the top of stack; prints element at last index of array (removes and replaces)
empty? => returns true or false based on if stack size is greater 0 or equal to 0
search => pops from a stack until a matching element is found and returns its position within the stack or if its not in the stack returns -1
|
| Describe a Queue | a data structure that uses FIFO (last in, first out) methods to add, access, and remove elements |
| What are the 5 methods in Queue and what does each do? |
enqueue => adds an element to back of queue
dequeue => removes an element from front of queue
peek => when queue is empty, stores the first element inside to variable and calls it without disturbing stack
empty? => if nothing is one the stack, returns true or false
size => current number that is held within queue
|
| What is the difference between implementing something and using something? |
N/A |
OPTIONAL JobSimulation