From feb025300ce464322f5e5400fb9b2b8a4e8a2a8a Mon Sep 17 00:00:00 2001 From: ame Date: Mon, 16 Oct 2023 01:44:07 -0500 Subject: use heap over stack --- t.lua | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 't.lua') diff --git a/t.lua b/t.lua index 2e906db..aef5ad1 100644 --- a/t.lua +++ b/t.lua @@ -3,8 +3,8 @@ local a = llib.array local tab = {} math.randomseed(os.time()) -for i=1,9999 do - table.insert(tab,math.random(1,999));-- + math.random(1,999)); +for i=1,19 do + table.insert(tab,math.random(1,99999));-- + math.random(1,999)); end print("length of 99999 :\n") @@ -17,9 +17,9 @@ print("merge sort took "..os.clock()-time.."s") time = os.clock() local l3 = a.shellsort(tab) print("shell sort took "..os.clock()-time.."s") -time = os.clock() -local l4 = a.bubblesort(tab) -print("bubble sort took "..os.clock()-time.."s") +--time = os.clock() +--local l4 = a.bubblesort(tab) +--print("bubble sort took "..os.clock()-time.."s") time = os.clock() local l5 = a.heapsort(tab) print("heap sort took "..os.clock()-time.."s") @@ -27,14 +27,7 @@ time = os.clock() local l6 = a.countingsort(tab) print("counting sort took "..os.clock()-time.."s") -for l,i in pairs(llib.array.reverse(l1)) do - --print(l1[l].." "..l2[l].." "..l3[l].." "..l4[l].." "..l5[l]) -end ---print(llib.array.greatest(l1)) ---local l2 = llib.array.reverse(llib.array.bubblesort(tab)) ---[[ aa for l,i in pairs(l1) do - print(l1[l].." "..l2[l]) + print(l1[l].." "..l2[l].." "..l3[l].." "..l5[l].." "..l6[l]) end -print(table.concat(l1) == table.concat(l2)) ]]-- -- cgit v1.2.3