Lynn Griffin - Edge : passed all test; created helper function for postfix_expression logic#20
Lynn Griffin - Edge : passed all test; created helper function for postfix_expression logic#20griffifam wants to merge 1 commit intoAda-C11:masterfrom
Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
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 = { |
| end | ||
| end | ||
|
|
||
| def arithmetic(first_num, second_num, exp) |
|
|
||
| def enqueue(element) | ||
| raise NotImplementedError, "Not yet implemented" | ||
| if @back == @front - 1 |
There was a problem hiding this comment.
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.
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.
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.
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.
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