Skip to content

Commit ceb7540

Browse files
committed
Fix requires
1 parent 8676c56 commit ceb7540

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

algorithms/sort_stack.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# an additional temporary stack, but you may not copy the elements into any other data structure
44
# (such as an array). The stack supports the following operations: push, pop, peek, and isEmpty.
55

6-
class Stack
6+
class SortStack
77
attr_reader :size
88

99
def initialize
@@ -36,7 +36,7 @@ def empty?
3636
def sort
3737
return self if empty?
3838

39-
temp = Stack.new
39+
temp = SortStack.new
4040
temp.push pop
4141

4242
until empty?

data-structures/queue_using_two_stacks.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# CtCI 6th Edition Problem 3.4
22
# Queue via Stacks: Implement a MyQueue class which implements a queue using two stacks.
33

4-
class Stack
4+
class MyStack
55
attr_reader :size
66

77
def initialize
@@ -15,15 +15,16 @@ def push(el)
1515
end
1616

1717
def pop
18+
return if @size.zero?
1819
@size -= 1
1920
@stack.pop
2021
end
2122
end
2223

2324
class MyQueue
2425
def initialize
25-
@push_stack = Stack.new
26-
@pop_stack = Stack.new
26+
@push_stack = MyStack.new
27+
@pop_stack = MyStack.new
2728
end
2829

2930
def add(item)

spec/algorithms/sort_stack_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
require_relative '../../algorithms/sort_stack'
1+
require './algorithms/sort_stack'
22

33
describe 'Stack#sort' do
4-
it 'sorts elements of a stack so that the smallest elements on on top' do
5-
stack = Stack.new
4+
it 'sorts elements of a stack so that the smallest elements is on top' do
5+
stack = SortStack.new
66
first_ten = (0..9).to_a
77
first_ten.each { |n| stack.push n }
88
sorted_stack = stack.sort

spec/data-structures/queue_using_two_stacks_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative '../../data-structures/queue_using_two_stacks'
1+
require './data-structures/queue_using_two_stacks'
22

33
describe 'Queue using two stacks' do
44
it 'adds items and removes them in the order they were added (FIFO)' do

0 commit comments

Comments
 (0)