diff options
author | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-02-17 23:34:58 +0000 |
---|---|---|
committer | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-02-17 23:34:58 +0000 |
commit | 337b5915e7092d6479004ae4771297aa4555cb14 (patch) | |
tree | f753cfc375cd72b5435fc77fa8bf8f8c6bb06a5f | |
parent | 8c2a6725d4dd95398da287d54bde6b4ef08f8688 (diff) |
Sat, Feb 17, 2024, 3:34 PM -08:00
-rw-r--r-- | wk3/lab/bubble.c | 2 | ||||
-rw-r--r-- | wk3/lab/selection.c | 9 |
2 files changed, 6 insertions, 5 deletions
diff --git a/wk3/lab/bubble.c b/wk3/lab/bubble.c index 6d6c5bb..2fceb37 100644 --- a/wk3/lab/bubble.c +++ b/wk3/lab/bubble.c @@ -15,5 +15,5 @@ int main(void) { repeat until completely sorted worst sorting method - O(n) + O(n^2) */ diff --git a/wk3/lab/selection.c b/wk3/lab/selection.c index 93e1cc7..d740b59 100644 --- a/wk3/lab/selection.c +++ b/wk3/lab/selection.c @@ -5,11 +5,12 @@ #include <string.h> int main(void) { - int arr[] = - for (int i = 0; i < arr.length - 1; i++) { + int arr[] = + int n = arr.length + for (int i = 0; i < n - 1; i++) { int n; int m; - for (int j = i; j < arr.length - 1; j++) { + for (int j = i; j < n - 1; j++) { if (arr[j] < n || n === undefined) { n = arr[j]; m = j; @@ -28,5 +29,5 @@ int main(void) { swap the 1st value and the smallest value repeat - + O(n) */ |