class Algorithmable::Cups::StacksAndQueues::StackSorter
Public Class Methods
sort(stack)
click to toggle source
# File lib/algorithmable/cups/stacks_and_queues/stack_sorter.rb, line 7 def self.sort(stack) new.sort(stack) end
Public Instance Methods
sort(stack)
click to toggle source
# File lib/algorithmable/cups/stacks_and_queues/stack_sorter.rb, line 11 def sort(stack) local_stack = new_lifo_queue until stack.empty? temp = stack.pop while !local_stack.empty? && local_stack.peek < temp stack.push local_stack.pop end local_stack.push temp end local_stack end