
#演示 链表(LinkedList) 的用法

#初始化 MKScript 窗口大小
mkscript_window_initial_size(500, 800)

#链表变量定义
LinkedList<string> list = {"1", "2", "3", "5", "6", "7", "8", "9"}

println("linkedlist_get_size(list):" + linkedlist_get_size(list))
println(list)

linkedlist_add(list, "9")
println(list)

linkedlist_insert(list, 3, "4")
println(list)

linkedlist_add_first(list, "0")
println(list)

println("linkedlist_contains(list, 8):" + linkedlist_contains(list, "8"))
println("linkedlist_contains(list, 1):" + linkedlist_contains(list, "1"))
println("linkedlist_contains(list, 9):" + linkedlist_contains(list, "9"))

println("linkedlist_get(list, 0):" + linkedlist_get(list, 0))
println("linkedlist_get(list, 1):" + linkedlist_get(list, 1))

println("linkedlist_get_first(list):" + linkedlist_get_first(list))
println("linkedlist_get_last(list):" + linkedlist_get_last(list))


println("linkedlist_index_of(list, 3):" + linkedlist_index_of(list, "3"))
println("linkedlist_index_of(list, 9):" + linkedlist_index_of(list, "9"))

println("linkedlist_last_index_of(list, 3):" + linkedlist_last_index_of(list, "3"))
println("linkedlist_last_index_of(list, 9):" + linkedlist_last_index_of(list, "9"))


println("linkedlist_remove_index(list, 0):" + linkedlist_remove_index(list, 0))
println("linkedlist_remove_index(list, 3):" + linkedlist_remove_index(list, 3))

println(list)

println("linkedlist_remove(list, 9):" + linkedlist_remove(list, "3"))
println("linkedlist_remove(list, 9):" + linkedlist_remove(list, "9"))
println("linkedlist_remove(list, 9):" + linkedlist_remove(list, "9"))
println("linkedlist_remove(list, 9):" + linkedlist_remove(list, "9"))

println(list)

println("linkedlist_remove_first(list):" + linkedlist_remove_first(list))

println(list)

println("linkedlist_remove_last(list):" + linkedlist_remove_last(list))

println(list)

linkedlist_set(list, 3, "666")

println(list)

println("-------------")

string v

#迭代器遍历
Iterator<string> iter = linkedlist_iterator(list)

loop iterator_has_next(iter) == mkTrue

    v = iterator_next(iter)

    println("v:" + v)

endloop

println("-------------")

#for ... in 循环
for v in list

    println("v2:" + v)

next
