Name: Anonymous 2011-09-14 0:03
Alright, I'm trying to create a linked list in Lua, but I'm having a slight issue. I know how to do it, but not why it works.
Can someone explain the following line of code to me?
list = {next = list, value = v}
To create a linked list I would do something like the following.
for i = 1,5 do
local v = io.read()
list = {next = list, value = v}
end
Then to show it I would go.
do
local l = list
while l do
print(l.value)
l = list.next
end
end
One again, all of it makes sense except the following.
list = {next = list, value = v}
If anyone here knows how this works and can explain it that would be great.
Can someone explain the following line of code to me?
list = {next = list, value = v}
To create a linked list I would do something like the following.
for i = 1,5 do
local v = io.read()
list = {next = list, value = v}
end
Then to show it I would go.
do
local l = list
while l do
print(l.value)
l = list.next
end
end
One again, all of it makes sense except the following.
list = {next = list, value = v}
If anyone here knows how this works and can explain it that would be great.