alestane icon

Dictionary tree (empty confirm)

alestane | PRO | 02/03/14 03:39:33 PM UTC | 0 ⭐ | 323 👁️ | Never ⏰ | []
Lua |

430 B

|

None

|

0 👍

/

0 👎

local dictionary = {}
 
local function insertWord(dict, word)
    local head, tail = word:upper():match('^(%a)(%a*)$')
    if not head then return false; end
    if not dict[head] then dict[head] = {}; end
    if tail == '' then
        dict[head][''] = true
        return true
    else
        return insertWord(dict[head], tail)
    end
end
 
local function confirmWord(dict, word)
end
 
insertWord(dictionary, 'BAG')
 
print(confirmWord(dictionary, 'BAG'))

Comments