require"math"
-- straight insertion sort
a = {3,1,8,4,5,2,7,9,6}
local b = function()
local string
for i = 1, 9 do
print(a[i])
end
end
b()
local length = table.getn(a)
print("a is length : ",length)
local c = function()
for i = 2, length do
if a[i] < a[i-1] then
local temp = a[i]
local j = i
while j > 1 and (a[j-1] > temp) do
a[j] = a[j-1]
j = j - 1
end
a[j] = temp
end
end
end
print("straight insertion sort")
c()
b()
a = {3,1,8,4,5,2,7,9,6}
local d = function()
for i = 1,length - 1 do
for j = 1, length-i do
if a[j] > a[j+1] then
a[j], a[j+1] = a[j+1],a[j]
end
end
end
end
print("reset")
b()
print("Bubble sort")
d()
b()
a = {3,1,8,4,5,2,7,9,6}
local e = function()
for i = 1, length-1 do
local minlag = i
for j = i+1, length do
if a[j] < a[minlag] then
-- straight insertion sort
a = {3,1,8,4,5,2,7,9,6}
local b = function()
local string
for i = 1, 9 do
print(a[i])
end
end
b()
local length = table.getn(a)
print("a is length : ",length)
local c = function()
for i = 2, length do
if a[i] < a[i-1] then
local temp = a[i]
local j = i
while j > 1 and (a[j-1] > temp) do
a[j] = a[j-1]
j = j - 1
end
a[j] = temp
end
end
end
print("straight insertion sort")
c()
b()
a = {3,1,8,4,5,2,7,9,6}
local d = function()
for i = 1,length - 1 do
for j = 1, length-i do
if a[j] > a[j+1] then
a[j], a[j+1] = a[j+1],a[j]
end
end
end
end
print("reset")
b()
print("Bubble sort")
d()
b()
a = {3,1,8,4,5,2,7,9,6}
local e = function()
for i = 1, length-1 do
local minlag = i
for j = i+1, length do
if a[j] < a[minlag] then