class Algorithmable::DataStructs::LinkedList::Base
Attributes
front[R]
size[R]
Public Class Methods
new(collection = [])
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 7 def initialize(collection = []) @front = nil @back = nil @size = 0 collection.each { |item| push_front item } end
Public Instance Methods
clear!()
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 18 def clear! @front = nil @back = nil @size = 0 end
delete(_item)
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 52 def delete(_item) fail NotImplementedError end
empty?()
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 14 def empty? 0 == size end
find_intersect(_other)
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 72 def find_intersect(_other) fail NotImplementedError end
include?(item)
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 32 def include?(item) !search(item).nil? end
merge(_other_list)
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 68 def merge(_other_list) fail NotImplementedError end
merge!(_other_list)
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 64 def merge!(_other_list) fail NotImplementedError end
peek_back()
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 28 def peek_back @back && @back.item end
peek_front()
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 24 def peek_front @front && @front.item end
pop_back()
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 44 def pop_back fail NotImplementedError end
pop_front()
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 48 def pop_front fail NotImplementedError end
push_back(_item)
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 36 def push_back(_item) fail NotImplementedError end
push_front(_item)
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 40 def push_front(_item) fail NotImplementedError end
reverse!()
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 56 def reverse! fail NotImplementedError end
sort!()
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 60 def sort! fail NotImplementedError end
to_a()
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 80 def to_a each.map(&:item) end
to_s()
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 76 def to_s to_a.join('->') end
Private Instance Methods
each(&block)
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 96 def each(&block) nodes = [] node = @front until node.nil? nodes << node node = node.next end nodes.each(&block) end
new_node(_item, *_args)
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 106 def new_node(_item, *_args) fail NotImplementedError end
search(item)
click to toggle source
# File lib/algorithmable/data_structs/linked_list/base.rb, line 86 def search(item) return if empty? node = @front while node break if node.item == item node = node.next end node end