Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/problems.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
require_relative './stack.rb'

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)
# Space Complexity: O(1)
def balanced(string)
Comment on lines +3 to 5

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually shouldn't work. It doesn't even look at the values in the string

raise NotImplementedError, "Not implemented yet"
array = string.split("")
i = 0
j = -1
until i = array.length / 2
return false if i != j
i += 1
j -+ 1
end

return true

end

# Time Complexity: ?
Expand Down
13 changes: 6 additions & 7 deletions lib/queue.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
class Queue

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but it's not implemented with a circular buffer. I suggest you review the notes on circular buffers and just verify that you understand how it works.


def initialize
# @store = ...
raise NotImplementedError, "Not yet implemented"
@store = LinkedList.new
end

def enqueue(element)
raise NotImplementedError, "Not yet implemented"
@store.add_last(element)
end

def dequeue
raise NotImplementedError, "Not yet implemented"
@store.remove_first()
end

def front
raise NotImplementedError, "Not yet implemented"
#front??
end

def size
raise NotImplementedError, "Not yet implemented"
@store.length
end

def empty?
raise NotImplementedError, "Not yet implemented"
@store.empty?
end

def to_s
Expand Down
10 changes: 5 additions & 5 deletions lib/stack.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
class Stack

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

def initialize
# @store = ...
raise NotImplementedError, "Not yet implemented"
@store = LinkedList.new
end

def push(element)
raise NotImplementedError, "Not yet implemented"
@store.add_first(element)
end

def pop
raise NotImplementedError, "Not yet implemented"
element = @store.remove_first()
return element
end

def empty?
raise NotImplementedError, "Not yet implemented"
@store.empty?
end

def to_s
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
require_relative "../lib/queue.rb"
require_relative "../lib/stack.rb"
# Extra exercises
# require_relative "../lib/problems.rb"
require_relative "../lib/problems.rb"