So, I'm working on an assignment where a LinkedListNode class generates a linked list and prints the values to the user. What I am supposed to do is create a Stack class to 'push', 'pop', and reverse the linked list. The thing is, we are unable to use the array methods of .push, .pop, or anything else.
I have been thinking and trying to look up what to do for over a day and have no clue on where to even start. Could someone please point me in the right direction of just getting the push method started so I can get some traction and maybe catch on?
LinkedListNode class given:
class LinkedListNode
attr_accessor :value, :next_node
def initialize(value, next_node=nil)
@value = value
@next_node = next_node
end
end
Starting skeleton of Stack class given:
class Stack
attr_reader :data
def initialize
@data = nil
end
# Push an item onto the stack
def push(element)
# IMPLEMENT ME!
end
# Pop an item off the stack.
# Remove the last item that was pushed onto the
# stack and return it to the user
def pop
# IMPLEMENT ME
end
end
I am not trying to ask for the answer straight out, I just can't figure out where to go. Thank you in advance for any help!