summaryrefslogtreecommitdiff
path: root/unit/01/reverse.rb
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-18 15:15:04 -0600
committermo khan <mo.khan@gmail.com>2020-05-18 15:15:04 -0600
commit623a5cc389f21bc7974ee5a53a506cb8a95f3f03 (patch)
treea927c4e3ed79bfe11495f1e014c81350516ce4f2 /unit/01/reverse.rb
parent5743e4c4f4d2274e9f06d6a72e06b80fbc4a8f1a (diff)
re-arrange folders
Diffstat (limited to 'unit/01/reverse.rb')
-rw-r--r--unit/01/reverse.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/unit/01/reverse.rb b/unit/01/reverse.rb
new file mode 100644
index 0000000..a50f062
--- /dev/null
+++ b/unit/01/reverse.rb
@@ -0,0 +1,30 @@
+require 'bundler/inline'
+
+gemfile do
+ source 'https://rubygems.org'
+
+ gem 'minitest'
+end
+
+require 'minitest/autorun'
+
+=begin
+Suppose you have a Stack, s, that supports only the push(x) and pop() operations.
+Show how, using only a FIFO Queue, q, you can reverse the order of all elements in s.
+=end
+
+class Example < Minitest::Test
+ def test_valid
+ s = []
+ s.push('A')
+ s.push('B')
+ s.push('C')
+
+ q = Queue.new
+ 3.times { q.enq(s.pop) }
+
+ x = 3.times.map { q.deq }
+
+ assert x == ['C', 'B', 'A']
+ end
+end