Created
April 12, 2018 02:40
-
-
Save Ch4s3/93c72a43f1360da25404fa6f2de81eef to your computer and use it in GitHub Desktop.
Revisions
-
Ch4s3 created this gist
Apr 12, 2018 .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,27 @@ class DoubleStack attr_accessor :inbox, :outbox def initialize @inbox = [] @outbox = [] end def enqueue(item) @inbox << item end def dequeue transfer if @outbox.empty? @outbox.pop end def front transfer if @outbox.empty? @outbox.last end private def transfer (1..@inbox.length).each { @outbox << @inbox.pop } end end