Last active
July 31, 2019 21:29
-
-
Save jasonknight/fc7fe23b5f4dfc929636b9ccbebc8ae6 to your computer and use it in GitHub Desktop.
Revisions
-
jasonknight revised this gist
Jul 31, 2019 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,8 +21,8 @@ def pop return node end end def reverse_nodes(stack) return stack.data end def print_values(node) if node @@ -43,5 +43,5 @@ def print_values(node) node = node.next_node end print_values(reverse_nodes(s)) -
jasonknight revised this gist
Jul 31, 2019 . 1 changed file with 2 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,14 +21,8 @@ def pop return node end end def reverse_odes(stack) return stack.data end def print_values(node) if node -
jasonknight renamed this gist
Jul 31, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jasonknight created this gist
Jul 31, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ class Node attr_accessor :value,:next_node def initialize(val,nxt) @value = val @next_node = nxt end end class Stack attr_accessor :data def initialize(d=nil) @data = d end def push(node) node.next_node = @data @data = node end def pop return @data if not @data node = @data @data = @data.next_node return node end end def reverseNodes(stack) root = stack.pop node = root while node node.next_node = stack.pop node = node.next_node end return root end def print_values(node) if node print "#{node.value} --> " print_values(node.next_node) else print "nil\n" end end s = Stack.new ll = Node.new(1,Node.new(2,Node.new(3,nil))) print_values(ll) node = ll while node s.push(node.clone) # because ruby passes by reference! node = node.next_node end print_values(s.data)