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
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

Choose a reason for hiding this comment

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

This all works, but isn't done with a circular buffer as assigned. So many of the methods end up with O(n) time complexity instead of O(1).


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

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

def dequeue
raise NotImplementedError, "Not yet implemented"
return @store.shift
end

def front
raise NotImplementedError, "Not yet implemented"
return @store[0]
end

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

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

def to_s
Expand Down
9 changes: 4 additions & 5 deletions lib/stack.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
class Stack
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"
@store.remove_first
end

def empty?
raise NotImplementedError, "Not yet implemented"
return @store.length == 0
end

def to_s
Expand Down