From c2706ac7d8df6461e5f30f2831c3da216fb80f64 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Thu, 18 Jan 2024 17:06:33 +0000 Subject: [PATCH 01/21] added WarmUp_10 --- CMakeLists.txt | 1 + WarmUp_10/CMakeLists.txt | 4 ++++ WarmUp_10/print_args.c | 8 ++++++++ 3 files changed, 13 insertions(+) create mode 100644 WarmUp_10/CMakeLists.txt create mode 100644 WarmUp_10/print_args.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c446e4d..3115807 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ add_subdirectory(hello-lib) add_subdirectory(lwlog-lib) add_subdirectory(lwlog-demo) add_subdirectory(gtest-demo) +add_subdirectory(WarmUp_10) # You can use add_subdirectory() to add your own work. # Please don't remove the existing subdirectories. diff --git a/WarmUp_10/CMakeLists.txt b/WarmUp_10/CMakeLists.txt new file mode 100644 index 0000000..4c52a0b --- /dev/null +++ b/WarmUp_10/CMakeLists.txt @@ -0,0 +1,4 @@ + +add_executable( + print_args + print_args.c) diff --git a/WarmUp_10/print_args.c b/WarmUp_10/print_args.c new file mode 100644 index 0000000..a49d989 --- /dev/null +++ b/WarmUp_10/print_args.c @@ -0,0 +1,8 @@ +#include +#include + +int main(int argc, char *argv[]) { + for (int i=1; i < argc; i++) { + printf("i=%d argv[%d] = %s\n", i, i, argv[i]); + } +} \ No newline at end of file From b5a6a6e93c516e0cc946474a9c18e67e3dffa970 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Tue, 23 Jan 2024 16:51:26 +0000 Subject: [PATCH 02/21] Add WarmUp_1 --- WarmUp_1/CMakeLists.txt | 3 +++ WarmUp_1/hello_world.c | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 WarmUp_1/CMakeLists.txt create mode 100644 WarmUp_1/hello_world.c diff --git a/WarmUp_1/CMakeLists.txt b/WarmUp_1/CMakeLists.txt new file mode 100644 index 0000000..fb1e995 --- /dev/null +++ b/WarmUp_1/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable( + hello_world + hello_world.c) diff --git a/WarmUp_1/hello_world.c b/WarmUp_1/hello_world.c new file mode 100644 index 0000000..41391df --- /dev/null +++ b/WarmUp_1/hello_world.c @@ -0,0 +1,7 @@ +#include +#include + +int main(int argc, char * * argv) { + printf("Hello, World!\n"); + return EXIT_SUCCESS; +} \ No newline at end of file From 421c1af55cf1a0baa33868bbe0edd0de839e264b Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Tue, 23 Jan 2024 16:53:11 +0000 Subject: [PATCH 03/21] Add WarmUp_1 --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3115807..233b2ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ add_subdirectory(lwlog-lib) add_subdirectory(lwlog-demo) add_subdirectory(gtest-demo) add_subdirectory(WarmUp_10) +add_subdirectory(WarmUp_1) # You can use add_subdirectory() to add your own work. # Please don't remove the existing subdirectories. From 1426448eb7c351fd7ff9c07e4d8cccfd1c9b8116 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Tue, 23 Jan 2024 17:16:46 +0000 Subject: [PATCH 04/21] add Warm Up 2 --- .vscode/settings.json | 5 +++++ WarmUp_2/CMakeLists.txt | 3 +++ 2 files changed, 8 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 WarmUp_2/CMakeLists.txt diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b242572 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "githubPullRequests.ignoredPullRequestBranches": [ + "main" + ] +} \ No newline at end of file diff --git a/WarmUp_2/CMakeLists.txt b/WarmUp_2/CMakeLists.txt new file mode 100644 index 0000000..dace314 --- /dev/null +++ b/WarmUp_2/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable( + basic_calculator + basic_calculator.c) From cb03faeb2d4e18912aa968b4db9d3c67ec4a3c1c Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Tue, 23 Jan 2024 18:35:39 +0000 Subject: [PATCH 05/21] added Warm Up 2 --- WarmUp_2/basic_calculator.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 WarmUp_2/basic_calculator.c diff --git a/WarmUp_2/basic_calculator.c b/WarmUp_2/basic_calculator.c new file mode 100644 index 0000000..db6af2f --- /dev/null +++ b/WarmUp_2/basic_calculator.c @@ -0,0 +1,19 @@ +#include +#include + +int main(void) { + double a, b; + + printf("Enter first number: "); + scanf("%lf", &a); + + printf("Enter second number: "); + scanf("%lf", &b); + + printf("Sum: %lf\n", a + b); + printf("Difference: %lf\n", a - b); + printf("Product: %lf\n", a * b); + printf("Quotient: %lf\n", a / b); + + return 0; +} \ No newline at end of file From f79992ecfefc48c6d9853f226afee9b9c443f84c Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Thu, 25 Jan 2024 16:26:44 +0000 Subject: [PATCH 06/21] Add subdirectory WarmUp_2 --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 233b2ab..f291680 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ add_subdirectory(lwlog-demo) add_subdirectory(gtest-demo) add_subdirectory(WarmUp_10) add_subdirectory(WarmUp_1) +add_subdirectory(WarmUp_2) # You can use add_subdirectory() to add your own work. # Please don't remove the existing subdirectories. From abab3c939fa080442b81a1d82012dfcd6ea7279e Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Thu, 25 Jan 2024 16:29:48 +0000 Subject: [PATCH 07/21] Add WarmUp_3 --- WarmUp_3/CMakeLists.txt | 3 +++ WarmUp_3/array_operations.c | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 WarmUp_3/CMakeLists.txt create mode 100644 WarmUp_3/array_operations.c diff --git a/WarmUp_3/CMakeLists.txt b/WarmUp_3/CMakeLists.txt new file mode 100644 index 0000000..f01edb9 --- /dev/null +++ b/WarmUp_3/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable( + array_operations + array_operations.c) \ No newline at end of file diff --git a/WarmUp_3/array_operations.c b/WarmUp_3/array_operations.c new file mode 100644 index 0000000..5fe3157 --- /dev/null +++ b/WarmUp_3/array_operations.c @@ -0,0 +1,6 @@ +#include +#include + +int main(void) { + +} \ No newline at end of file From 0be9ab10e4b8251e56edecbd4b66119b5a83f397 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Thu, 25 Jan 2024 16:30:20 +0000 Subject: [PATCH 08/21] Add subdirectory WarmUp_3 --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f291680..4a3b8a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ add_subdirectory(gtest-demo) add_subdirectory(WarmUp_10) add_subdirectory(WarmUp_1) add_subdirectory(WarmUp_2) +add_subdirectory(WarmUp_3) # You can use add_subdirectory() to add your own work. # Please don't remove the existing subdirectories. From accaf8696ddab8bbe39a0e276c941a1a21228079 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Thu, 25 Jan 2024 16:36:18 +0000 Subject: [PATCH 09/21] Edit WarmUp_2 --- WarmUp_2/basic_calculator.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WarmUp_2/basic_calculator.c b/WarmUp_2/basic_calculator.c index db6af2f..0735cb2 100644 --- a/WarmUp_2/basic_calculator.c +++ b/WarmUp_2/basic_calculator.c @@ -1,7 +1,12 @@ #include #include -int main(void) { +int main(int argc, char * * argv) { + + if (argc < 2) { + printf("Need a number!\n"); + return EXIT_FAILURE; + } double a, b; printf("Enter first number: "); From 496aec95c275205a790fd3a55c26693cf34c2eaa Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Thu, 25 Jan 2024 17:05:42 +0000 Subject: [PATCH 10/21] Edit WarmUp_3 --- WarmUp_3/array_operations.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/WarmUp_3/array_operations.c b/WarmUp_3/array_operations.c index 5fe3157..4f71a1c 100644 --- a/WarmUp_3/array_operations.c +++ b/WarmUp_3/array_operations.c @@ -2,5 +2,9 @@ #include int main(void) { - + int numbers[5]; + int sum = 0; + float average; + + return 0; } \ No newline at end of file From d412ac7303431d0848adce635728f9bc30282b0a Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Thu, 25 Jan 2024 17:10:02 +0000 Subject: [PATCH 11/21] Edit WarmUp_3 --- WarmUp_3/array_operations.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/WarmUp_3/array_operations.c b/WarmUp_3/array_operations.c index 4f71a1c..35b9cb2 100644 --- a/WarmUp_3/array_operations.c +++ b/WarmUp_3/array_operations.c @@ -1,10 +1,17 @@ #include #include +#define SIZE 5 int main(void) { - int numbers[5]; + int index, numbers[SIZE]; int sum = 0; float average; + for (index = 0; index < SIZE; index++) + sum += score[index]; + average = (float) sum / SIZE; + + printf + return 0; } \ No newline at end of file From ac9f92adb76ac425825ad9c0b7e96ab0c6219749 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Sun, 28 Jan 2024 04:27:07 +0000 Subject: [PATCH 12/21] Edit WarmUp_3 --- WarmUp_3/array_operations.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/WarmUp_3/array_operations.c b/WarmUp_3/array_operations.c index 35b9cb2..0e63fe5 100644 --- a/WarmUp_3/array_operations.c +++ b/WarmUp_3/array_operations.c @@ -1,17 +1,14 @@ #include -#include -#define SIZE 5 -int main(void) { - int index, numbers[SIZE]; +int main() { + int numbers[] = {1, 2, 3, 4, 5}; int sum = 0; - float average; - - for (index = 0; index < SIZE; index++) - sum += score[index]; - average = (float) sum / SIZE; - - printf - + int length = sizeof(numbers) / sizeof(numbers[0]); + for (int i = 0; i < length; i++) { + sum += numbers[i]; + } + double average = sum / (double) length; + printf("Sum: %d\n", sum); + printf("Average: %f\n", average); return 0; } \ No newline at end of file From d98a572b5c9b90a06e5216982b40634b3e07f336 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Sun, 28 Jan 2024 15:47:37 +0000 Subject: [PATCH 13/21] Rename --- CMakeLists.txt | 2 +- Class_Example/CMakeLists.txt | 4 ++++ Class_Example/print_args.c | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 Class_Example/CMakeLists.txt create mode 100644 Class_Example/print_args.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a3b8a6..d151b1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ add_subdirectory(hello-lib) add_subdirectory(lwlog-lib) add_subdirectory(lwlog-demo) add_subdirectory(gtest-demo) -add_subdirectory(WarmUp_10) +add_subdirectory(Class_Example) add_subdirectory(WarmUp_1) add_subdirectory(WarmUp_2) add_subdirectory(WarmUp_3) diff --git a/Class_Example/CMakeLists.txt b/Class_Example/CMakeLists.txt new file mode 100644 index 0000000..4c52a0b --- /dev/null +++ b/Class_Example/CMakeLists.txt @@ -0,0 +1,4 @@ + +add_executable( + print_args + print_args.c) diff --git a/Class_Example/print_args.c b/Class_Example/print_args.c new file mode 100644 index 0000000..81ff0ad --- /dev/null +++ b/Class_Example/print_args.c @@ -0,0 +1,7 @@ +#include +#include + +int main(int argc, char *argv[]) { + for (int i=1; i < argc; i++) { + printf("i=%d argv[%d] = %s\n", i, i, argv[i]); + } \ No newline at end of file From cd2ec84641b3b9d29576cb355f3f64b0c47d5b39 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Sun, 28 Jan 2024 16:05:46 +0000 Subject: [PATCH 14/21] Add WarmUp_10 --- WarmUp_10/CMakeLists.txt | 5 ++--- WarmUp_10/command_line.c | 8 ++++++++ WarmUp_10/print_args.c | 7 ------- 3 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 WarmUp_10/command_line.c delete mode 100644 WarmUp_10/print_args.c diff --git a/WarmUp_10/CMakeLists.txt b/WarmUp_10/CMakeLists.txt index 4c52a0b..e13d58e 100644 --- a/WarmUp_10/CMakeLists.txt +++ b/WarmUp_10/CMakeLists.txt @@ -1,4 +1,3 @@ - add_executable( - print_args - print_args.c) + command_line + command_line.c) \ No newline at end of file diff --git a/WarmUp_10/command_line.c b/WarmUp_10/command_line.c new file mode 100644 index 0000000..0852e9b --- /dev/null +++ b/WarmUp_10/command_line.c @@ -0,0 +1,8 @@ +#include + +int main(int argc, char *argv[]) { + for (int i = 1; i < argc; i++) { + printf("%s\n", argv[i]); + } + return 0; +} \ No newline at end of file diff --git a/WarmUp_10/print_args.c b/WarmUp_10/print_args.c deleted file mode 100644 index 81ff0ad..0000000 --- a/WarmUp_10/print_args.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int main(int argc, char *argv[]) { - for (int i=1; i < argc; i++) { - printf("i=%d argv[%d] = %s\n", i, i, argv[i]); - } \ No newline at end of file From 6fd8d48493386f9ed8671d4155eb7eec9e564209 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Sun, 28 Jan 2024 16:26:43 +0000 Subject: [PATCH 15/21] Add WarmUp_4 --- WarmUp_4/CMakeLists.txt | 3 +++ WarmUp_4/reverse_string.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 WarmUp_4/CMakeLists.txt create mode 100644 WarmUp_4/reverse_string.c diff --git a/WarmUp_4/CMakeLists.txt b/WarmUp_4/CMakeLists.txt new file mode 100644 index 0000000..beecb29 --- /dev/null +++ b/WarmUp_4/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable( + reverse_string + reverse_string.c) \ No newline at end of file diff --git a/WarmUp_4/reverse_string.c b/WarmUp_4/reverse_string.c new file mode 100644 index 0000000..da1a7f0 --- /dev/null +++ b/WarmUp_4/reverse_string.c @@ -0,0 +1,14 @@ +#include +#include + +int main() { + char str[] = "Hello"; + int length = strlen(str); + for (int i = 0, x = length - 1; i < x; i++, x--) { + char temp = str[i]; + str[i] = str[x]; + str[x] = temp; + } + printf("%s\n", str); + return 0; +} \ No newline at end of file From ddf7aae2f7b5c67ea20c1a3a56048eee0cdbdac0 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Sun, 28 Jan 2024 16:58:15 +0000 Subject: [PATCH 16/21] Add WarmUp_9 --- CMakeLists.txt | 8 +++++++- WarmUp_9/CMakeLists.txt | 3 +++ WarmUp_9/file_operations.c | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 WarmUp_9/CMakeLists.txt create mode 100644 WarmUp_9/file_operations.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d151b1e..ab4dbff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,13 @@ add_subdirectory(Class_Example) add_subdirectory(WarmUp_1) add_subdirectory(WarmUp_2) add_subdirectory(WarmUp_3) - +add_subdirectory(WarmUp_4) +add_subdirectory(WarmUp_5) +add_subdirectory(WarmUp_6) +add_subdirectory(WarmUp_7) +add_subdirectory(WarmUp_8) +add_subdirectory(WarmUp_9) +add_subdirectory(WarmUp_10) # You can use add_subdirectory() to add your own work. # Please don't remove the existing subdirectories. diff --git a/WarmUp_9/CMakeLists.txt b/WarmUp_9/CMakeLists.txt new file mode 100644 index 0000000..8155d20 --- /dev/null +++ b/WarmUp_9/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable( + file_operations + file_operations.c) \ No newline at end of file diff --git a/WarmUp_9/file_operations.c b/WarmUp_9/file_operations.c new file mode 100644 index 0000000..3929243 --- /dev/null +++ b/WarmUp_9/file_operations.c @@ -0,0 +1,27 @@ +#include +#include + +int main() { + char filename[] = "example.txt"; + FILE *fp = fopen(filename, "w"); + if (fp == NULL) { + perror("Error opening file."); + return EXIT_FAILURE; + } + fprintf(fp, "Hello, World!"); + fclose(fp); + + fp = fopen(filename, "r"); + if (fp == NULL) { + perror("Error opening file."); + return EXIT_FAILURE; + } + char line[256]; + while (fgets(line, sizeof(line), fp)) { + printf("%s", line); + } + fclose(fp); + + return 0; +} + From 4816c6af39391e4569fa20c1ce8fe042986b9f0e Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Sun, 28 Jan 2024 21:15:49 +0000 Subject: [PATCH 17/21] Add WarmUp_6 --- WarmUp_6/CMakeLists.txt | 3 +++ WarmUp_6/factorial.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 WarmUp_6/CMakeLists.txt create mode 100644 WarmUp_6/factorial.c diff --git a/WarmUp_6/CMakeLists.txt b/WarmUp_6/CMakeLists.txt new file mode 100644 index 0000000..b235348 --- /dev/null +++ b/WarmUp_6/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable( + factorial + factorial.c) \ No newline at end of file diff --git a/WarmUp_6/factorial.c b/WarmUp_6/factorial.c new file mode 100644 index 0000000..97a794d --- /dev/null +++ b/WarmUp_6/factorial.c @@ -0,0 +1,14 @@ +public class Factorial { + public static void main(String[] args) { + int number = 5; + System.out.println("Factorial of " + number + " is: " + factorial(number)); + } + + public static int factorial(int n) { + if (n <= 0) { + return 1; + } else { + return n * factorial(n - 1); + } + } +} From c0edf68ad1f116313861175c4212a3081aab4c70 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Sun, 28 Jan 2024 21:57:57 +0000 Subject: [PATCH 18/21] Add WarmUp_7 --- WarmUp_7/CMakeLists.txt | 3 +++ WarmUp_7/linear_search.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 WarmUp_7/CMakeLists.txt create mode 100644 WarmUp_7/linear_search.c diff --git a/WarmUp_7/CMakeLists.txt b/WarmUp_7/CMakeLists.txt new file mode 100644 index 0000000..238a858 --- /dev/null +++ b/WarmUp_7/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable( + linear_search + linear_search.c) \ No newline at end of file diff --git a/WarmUp_7/linear_search.c b/WarmUp_7/linear_search.c new file mode 100644 index 0000000..ddca749 --- /dev/null +++ b/WarmUp_7/linear_search.c @@ -0,0 +1,23 @@ +#include + +int linearSearch(int arr[], int length, int target) { + for (int i = 0; i < length; i++) { + if (arr[i] == target) { + return i; + } + } + return -1; +} + +int main() { + int array[] = {1, 4, 7, 9, 12}; + int target = 9; + int length = sizeof(array) / sizeof(array[0]); + int index = linearSearch(array, length, target); + if (index != -1) { + printf("Element found at index: %d\n", index); + } else { + printf("Element not found.\n"); + } + return 0; +} From b3c1e4a28ef5992dadc5ec50724d934a48771081 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Sun, 28 Jan 2024 22:53:49 +0000 Subject: [PATCH 19/21] add WarmUp_8 --- WarmUp_8/CMakeLists.txt | 3 ++ WarmUp_8/linked_lists.c | 63 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 WarmUp_8/CMakeLists.txt create mode 100644 WarmUp_8/linked_lists.c diff --git a/WarmUp_8/CMakeLists.txt b/WarmUp_8/CMakeLists.txt new file mode 100644 index 0000000..311c4d6 --- /dev/null +++ b/WarmUp_8/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable( + linked_lists + linked_lists.c) \ No newline at end of file diff --git a/WarmUp_8/linked_lists.c b/WarmUp_8/linked_lists.c new file mode 100644 index 0000000..183687c --- /dev/null +++ b/WarmUp_8/linked_lists.c @@ -0,0 +1,63 @@ +#include +#include + +struct Node { + int data; + struct Node* next; +}; + +void push(struct Node** head_ref, int new_data) { + struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); + new_node->data = new_data; + new_node->next = (*head_ref); + (*head_ref) = new_node; +} + +void deleteNode(struct Node **head_ref, int key) { + struct Node* temp = *head_ref, *prev; + if (temp != NULL && temp->data == key) { + *head_ref = temp->next; + free(temp); + return; + } + while (temp != NULL && temp->data != key) { + prev = temp; + temp = temp->next; + } + if (temp == NULL) return; + prev->next = temp->next; + free(temp); +} + +void printList(struct Node *node) { + while (node != NULL) { + printf("%d ", node->data); + node = node->next; + } +} + +void deleteList(struct Node** head_ref) { + struct Node* current = *head_ref; + struct Node* next; + while (current != NULL) { + next = current->next; + free(current); + current = next; + } + *head_ref = NULL; +} + +int main() { + struct Node* head = NULL; + push(&head, 7); + push(&head, 1); + push(&head, 3); + push(&head, 2); + printf("\nCreated Linked list is: \n"); + printList(head); + deleteNode(&head, 1); + printf("\nLinked List after Deletion of 1: \n"); + printList(head); + deleteList(&head); + return 0; +} From d240818e5a040a8c26d727628f0413ebbf0a8b3a Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Mon, 29 Jan 2024 00:25:04 +0000 Subject: [PATCH 20/21] add WarmUp_5 --- WarmUp_5/CMakeLists.txt | 3 +++ WarmUp_5/matrix_operations.c | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 WarmUp_5/CMakeLists.txt create mode 100644 WarmUp_5/matrix_operations.c diff --git a/WarmUp_5/CMakeLists.txt b/WarmUp_5/CMakeLists.txt new file mode 100644 index 0000000..af7cbaf --- /dev/null +++ b/WarmUp_5/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable( + matrix_operations + matrix_operations.c) \ No newline at end of file diff --git a/WarmUp_5/matrix_operations.c b/WarmUp_5/matrix_operations.c new file mode 100644 index 0000000..404e362 --- /dev/null +++ b/WarmUp_5/matrix_operations.c @@ -0,0 +1,46 @@ +#include + +void addMatrices(int rows, int columns, int a[rows][columns], int b[rows][columns], int sum[rows][columns]) { + for (int i = 0; i < rows; i++) { + for (int x = 0; x < columns; x++) { + sum[i][x] = a[i][x] + b[i][x]; + } + } +} + +void multiplyMatrices(int aRows, int aColumns, int bColumns, int a[aRows][aColumns], int b[aColumns][bColumns], int product[aRows][bColumns]) { + for (int i = 0; i < aRows; i++) { + for (int x = 0; x < bColumns; x++) { + product[i][x] = 0; + for (int y = 0; y < aColumns; y++) { + product[i][x] += a[i][y] * b[y][x]; + } + } + } +} + +void printMatrix(int rows, int columns, int matrix[rows][columns]) { + for (int i = 0; i < rows; i++) { + for (int x = 0; x < columns; x++) { + printf("%d ", matrix[i][x]); + } + printf("\n"); + } +} + +int main() { + int matrix1[2][2] = {{1, 2}, {3, 4}}; + int matrix2[2][2] = {{5, 6}, {7, 8}}; + int sum[2][2]; + int product[2][2]; + + addMatrices(2, 2, matrix1, matrix2, sum); + multiplyMatrices(2, 2, 2, matrix1, matrix2, product); + + printf("Matrix Addition:\n"); + printMatrix(2, 2, sum); + printf("Matrix Multiplication:\n"); + printMatrix(2, 2, product); + + return 0; +} From b775c1cf54503052a0d72bf08ce3b559363a9948 Mon Sep 17 00:00:00 2001 From: Ella McKenney Date: Thu, 8 Feb 2024 10:35:05 -0600 Subject: [PATCH 21/21] Update README in class --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d62688b..25a38d5 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,6 @@ This is a starter repository for COMP 310 (Operating Systems) students. You shou ## Learning objectives - Programming in C -- Separate compilation +- Separate compilation- Build automation using CMake - Build automation using CMake - Unit testing using GoogleTest