Skip to content

Commit 58c7a5c

Browse files
author
Shawn Bragdon
committed
Update documentation on the functions.
1 parent 1244068 commit 58c7a5c

File tree

17 files changed

+264
-163
lines changed

17 files changed

+264
-163
lines changed

.vscode/settings.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"files.associations": {
3+
"algorithm": "cpp",
4+
"array": "cpp",
5+
"atomic": "cpp",
6+
"bit": "cpp",
7+
"cctype": "cpp",
8+
"clocale": "cpp",
9+
"cmath": "cpp",
10+
"compare": "cpp",
11+
"concepts": "cpp",
12+
"cstddef": "cpp",
13+
"cstdint": "cpp",
14+
"cstdio": "cpp",
15+
"cstdlib": "cpp",
16+
"cstring": "cpp",
17+
"ctime": "cpp",
18+
"cwchar": "cpp",
19+
"exception": "cpp",
20+
"functional": "cpp",
21+
"initializer_list": "cpp",
22+
"iomanip": "cpp",
23+
"ios": "cpp",
24+
"iosfwd": "cpp",
25+
"iostream": "cpp",
26+
"istream": "cpp",
27+
"iterator": "cpp",
28+
"limits": "cpp",
29+
"list": "cpp",
30+
"memory": "cpp",
31+
"new": "cpp",
32+
"ostream": "cpp",
33+
"sstream": "cpp",
34+
"stdexcept": "cpp",
35+
"streambuf": "cpp",
36+
"string": "cpp",
37+
"system_error": "cpp",
38+
"tuple": "cpp",
39+
"type_traits": "cpp",
40+
"typeinfo": "cpp",
41+
"unordered_map": "cpp",
42+
"unordered_set": "cpp",
43+
"utility": "cpp",
44+
"vector": "cpp",
45+
"xfacet": "cpp",
46+
"xhash": "cpp",
47+
"xiosbase": "cpp",
48+
"xlocale": "cpp",
49+
"xlocinfo": "cpp",
50+
"xlocmon": "cpp",
51+
"xlocnum": "cpp",
52+
"xloctime": "cpp",
53+
"xmemory": "cpp",
54+
"xstddef": "cpp",
55+
"xstring": "cpp",
56+
"xtr1common": "cpp",
57+
"xutility": "cpp"
58+
}
59+
}

sortingAlgo/bubbleSort/bubbleSort.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
--- Sort an array using the bubble sort algorithm.
2+
--- @param t table
3+
--- @return table
14
local function bubbleSort(t)
25
local n = #t
36
for i = 1, n do
@@ -9,6 +12,10 @@ local function bubbleSort(t)
912
end
1013
end
1114

15+
--[[
1216
local t = { 3, 2, 1, 4, 5, 6, 7, 8, 9, 10 }
1317
bubbleSort(t)
14-
print(table.concat(t, ", "))
18+
print(table.concat(t, ", "))
19+
]]
20+
21+
return bubbleSort

sortingAlgo/bucketsort/bucketSort.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
--- Sort an array using the bucket sort algorithm.
2+
--- @param t table
3+
--- @return table
14
local function bucketSort(t)
25
local n = #t
36
local buckets = {}
@@ -20,8 +23,7 @@ local function bucketSort(t)
2023
end
2124
end
2225
end
26+
return t
2327
end
2428

25-
local t = { 0.3, 0.2, 0.1, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1 }
26-
bucketSort(t)
27-
print(table.concat(t, ", "))
29+
return bucketSort

sortingAlgo/cocktailSort/cocktailSort.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
--- Sort an array using the cocktail sort algorithm.
2+
--- @param t table
3+
--- @return table
14
local function cocktailSort(t)
25
local n = #t
36
local swapped = true
@@ -24,8 +27,7 @@ local function cocktailSort(t)
2427
end
2528
start = start + 1
2629
end
30+
return t
2731
end
2832

29-
local t = { 3, 2, 1, 4, 5, 6, 7, 8, 9, 10 }
30-
cocktailSort(t)
31-
print(table.concat(t, ", "))
33+
return cocktailSort

sortingAlgo/combSort/combSort.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
--- Sort an array using comb sort algorithm.
2+
--- @param t table
3+
--- @return table
14
local function combSort(t)
25
local n = #t
36
local gap = n
@@ -16,8 +19,7 @@ local function combSort(t)
1619
end
1720
end
1821
end
22+
return t
1923
end
2024

21-
local t = { 3, 2, 1, 4, 5, 6, 7, 8, 9, 10 }
22-
combSort(t)
23-
print(table.concat(t, ", "))
25+
return combSort

sortingAlgo/countingSort/countingSort.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
--- Sort an array using counting sort algorithm.
2+
--- @param t table
3+
--- @return table
14
local function countingSort(t)
25
local n = #t
36
local counts = {}
@@ -13,8 +16,7 @@ local function countingSort(t)
1316
end
1417
end
1518
end
19+
return t
1620
end
1721

18-
local t = { 3, 2, 1, 4, 5, 6, 7, 8, 9, 10 }
19-
countingSort(t)
20-
print(table.concat(t, ", "))
22+
return countingSort

sortingAlgo/cycleSort/cycleSort.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
--- Sort an array using cycle sort algorithm.
2+
--- @param t table
3+
--- @return table
14
local function cycleSort(t)
25
local n = #t
36
for i = 1, n do
@@ -29,8 +32,7 @@ local function cycleSort(t)
2932
t[pos], item = item, t[pos]
3033
end
3134
end
35+
return t
3236
end
3337

34-
local t = { 3, 2, 1, 4, 5, 6, 7, 8, 9, 10 }
35-
cycleSort(t)
36-
print(table.concat(t, ", "))
38+
return cycleSort

sortingAlgo/insertionSort/insertionSort.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
--- Sort an array using the insertion sort algorithm.
2+
--- @param t table
3+
--- @return table
14
local function insertionSort(t)
25
local n = #t
36
for i = 2, n do
@@ -9,8 +12,7 @@ local function insertionSort(t)
912
end
1013
t[j + 1] = item
1114
end
15+
return t
1216
end
1317

14-
local t = { 3, 2, 1, 4, 5, 6, 7, 8, 9, 10 }
15-
insertionSort(t)
16-
print(table.concat(t, ", "))
18+
return insertionSort

sortingAlgo/mergeSort/mergeSort.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
--- Sort an array using the merge sort algorithm.
2+
--- @param t table
3+
--- @return table
14
local function mergeSort(t)
25
local n = #t
36
if n < 2 then
@@ -40,6 +43,4 @@ local function mergeSort(t)
4043
return t
4144
end
4245

43-
local t = { 3, 2, 1, 4, 5, 6, 7, 8, 9, 10 }
44-
mergeSort(t)
45-
print(table.concat(t, ", "))
46+
return mergeSort

sortingAlgo/pigeonholeSort/pigeonholeSort.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
--- Sort an array using the pigeonhole sort algorithm.
2+
--- @param t table
3+
--- @return table
14
local function pigeonholeSort(t)
25
local n = #t
36
local min = math.huge
@@ -25,8 +28,7 @@ local function pigeonholeSort(t)
2528
holes[i] = holes[i] - 1
2629
end
2730
end
31+
return t
2832
end
2933

30-
local t = { 3, 2, 1, 4, 5, 6, 7, 8, 9, 10 }
31-
pigeonholeSort(t)
32-
print(table.concat(t, ", "))
34+
return pigeonholeSort

0 commit comments

Comments
 (0)