LUA: one-way linked list data structure (a)

Recommended for you: Get network issues from WhatsUp Gold. Not end users.


In LUA, the table is an advanced complex data structures useful, LUA module, arrays, associative arrays are created by table. Now we come to have a look to construct a one-way linked list by table. .
To construct a one-way list
In LUA, create table object initialized, the reference to a variable, namely the table address. The variable is a pointer variable pointing to table. For example, L= {1,2}, L is the pointer variable. Below we have a look on how to create a one-way linked list.
1: -- Singly-linked list in LUA 2: 3: for line in io.lines() do 4: L = { next = L,text = line } 5: end as above, the table address to the next preserved.
Reading list
1: -- Reading the Singly-linked list in LUA 2: 3: while L do 4: print(L.text) 5: L = 6: end Summary
LUA as a scripting language, is mainly used to provide software (game) adjustment flexibility, often used in conjunction with C/C++. Because the compiled language to modify the code need to compile, but LUA can directly modify, loading can be executed again. Reduces the commission cost.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Beck at December 06, 2013 - 2:18 PM