Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
|
|
@ -0,0 +1,26 @@
|
|||
class Node (T)
|
||||
property data : T
|
||||
property next : Node(T)?
|
||||
|
||||
def initialize (@data, @next = nil)
|
||||
end
|
||||
|
||||
def insert_after (new_data)
|
||||
n = Node.new(new_data, @next)
|
||||
@next = n
|
||||
end
|
||||
|
||||
def to_s (io)
|
||||
io << data << "->"
|
||||
if @next
|
||||
@next.to_s(io)
|
||||
else
|
||||
io << "."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
n = Node.new('A', Node.new('B', Node.new('D')))
|
||||
puts n
|
||||
n.insert_after('C')
|
||||
puts n
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
require "list"
|
||||
|
||||
local s = slist.of("A", "B")
|
||||
local ixs = s:find("A") -- always returns an array of indices even if we only want the first
|
||||
if #ixs > 0 then
|
||||
s:insert(ixs[1] + 1, "C")
|
||||
print(s)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue