diff --git a/.gitignore b/.gitignore deleted file mode 100644 index f433d36..0000000 --- a/.gitignore +++ /dev/null @@ -1,54 +0,0 @@ -.vscode/ - -# Prerequisites -*.d - -# Object files -*.o -*.ko -*.obj -*.elf - -# Linker output -*.ilk -*.map -*.exp - -# Precompiled Headers -*.gch -*.pch - -# Libraries -*.lib -*.a -*.la -*.lo - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - -# Debug files -*.dSYM/ -*.su -*.idb -*.pdb - -# Kernel Module Compile Results -*.mod* -*.cmd -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf diff --git a/Assignment/EX3.pdf b/Assignment/EX3.pdf deleted file mode 100644 index 90c3fdc..0000000 Binary files a/Assignment/EX3.pdf and /dev/null differ diff --git a/Assignment/StrList.h b/Assignment/StrList.h deleted file mode 100644 index 3b8889f..0000000 --- a/Assignment/StrList.h +++ /dev/null @@ -1,113 +0,0 @@ -#pragma once - -#include <stdlib.h> - -/******************************************************************************** - * - * A StrList library. - * - * This library provides a StrList of STRINGS data structure. - * - * This library will fail in unpredictable ways when the system memory runs - * out. - * - ********************************************************************************/ - -/* - * StrList represents a StrList data structure. - */ -struct _StrList; -typedef struct _StrList StrList; - -/* - * Allocates a new empty StrList. - * It's the user responsibility to free it with StrList_free. - */ -StrList* StrList_alloc(); - -/* - * Frees the memory and resources allocated to StrList. - * If StrList==NULL does nothing (same as free). - */ -void StrList_free(StrList* StrList); - -/* - * Returns the number of elements in the StrList. - */ -size_t StrList_size(const StrList* StrList); - -/* - * Inserts an element in the end of the StrList. - */ -void StrList_insertLast(StrList* StrList, - const char* data); - -/* -* Inserts an element at given index -*/ -void StrList_insertAt(StrList* StrList, - const char* data,int index); - -/* - * Returns the StrList first data. - */ -char* StrList_firstData(const StrList* StrList); - -/* - * Prints the StrList to the standard output. - */ -void StrList_print(const StrList* StrList); - -/* - Prints the word at the given index to the standard output. -*/ -void StrList_printAt(const StrList* Strlist,int index); - -/* - * Return the amount of chars in the list. -*/ -int StrList_printLen(const StrList* Strlist); - -/* -Given a string, return the number of times it exists in the list. -*/ -int StrList_count(StrList* StrList, const char* data); - -/* - Given a string and a list, remove all the appearences of this string in the list. -*/ -void StrList_remove(StrList* StrList, const char* data); - -/* - Given an index and a list, remove the string at that index. -*/ -void StrList_removeAt(StrList* StrList, int index); - -/* - * Checks if two StrLists have the same elements - * returns 0 if not and any other number if yes - */ -int StrList_isEqual(const StrList* StrList1, const StrList* StrList2); - -/* - * Clones the given StrList. - * It's the user responsibility to free it with StrList_free. - */ -StrList* StrList_clone(const StrList* StrList); - -/* - * Reverces the given StrList. - */ -void StrList_reverse( StrList* StrList); - -/* - * Sort the given list in lexicographical order - */ -void StrList_sort( StrList* StrList); - -/* - * Checks if the given list is sorted in lexicographical order - * returns 1 for sorted, 0 otherwise - */ -int StrList_isSorted(StrList* StrList); - diff --git a/Assignment/inputs_outputs/inputs/input1.txt b/Assignment/inputs_outputs/inputs/input1.txt deleted file mode 100644 index ed6df45..0000000 --- a/Assignment/inputs_outputs/inputs/input1.txt +++ /dev/null @@ -1,19 +0,0 @@ -1 -19 -Grace Hopper coined "bug" for computer glitches. In 1947, she found a moth causing issues in Harvard's Mark II. -3 -4 -13 -9 -5 -3 -6 -5 -5 -2 -5 -computer -3 -10 -3 -0 diff --git a/Assignment/inputs_outputs/inputs/input2.txt b/Assignment/inputs_outputs/inputs/input2.txt deleted file mode 100644 index 917ff5f..0000000 --- a/Assignment/inputs_outputs/inputs/input2.txt +++ /dev/null @@ -1,17 +0,0 @@ -1 -20 -Alan Turing's Turing machine concept laid the foundation for modern computing. His work influenced the development of computers and algorithms. -3 -4 -6 -7 -computers -8 -concept -3 -12 -3 -13 -11 -3 -0 diff --git a/Assignment/inputs_outputs/outputs/output1.txt b/Assignment/inputs_outputs/outputs/output1.txt deleted file mode 100644 index 89f7a1d..0000000 --- a/Assignment/inputs_outputs/outputs/output1.txt +++ /dev/null @@ -1,8 +0,0 @@ -Grace Hopper coined "bug" for computer glitches. In 1947, she found a moth causing issues in Harvard's Mark II. -19 -false -Grace Hopper coined "bug" for glitches. In 1947, she found a moth causing issues in Harvard's Mark II. -85 -glitches. -Grace Hopper coined "bug" for computer glitches. In 1947, she found a moth causing issues in Harvard's Mark II. -II. Mark Harvard's in issues causing moth a found she 1947, In glitches. computer for "bug" coined Hopper Grace diff --git a/Assignment/inputs_outputs/outputs/output2.txt b/Assignment/inputs_outputs/outputs/output2.txt deleted file mode 100644 index 6234eca..0000000 --- a/Assignment/inputs_outputs/outputs/output2.txt +++ /dev/null @@ -1,8 +0,0 @@ -Alan Turing's Turing machine concept laid the foundation for modern computing. His work influenced the development of computers and algorithms. -20 -124 -1 -Alan Turing's Turing machine laid the foundation for modern computing. His work influenced the development of computers and algorithms. -Alan His Turing Turing's algorithms. and computers computing. development for foundation influenced laid machine modern of the the work -true - diff --git a/Submission/Main.c b/Main.c similarity index 100% rename from Submission/Main.c rename to Main.c diff --git a/Submission/Makefile b/Makefile similarity index 73% rename from Submission/Makefile rename to Makefile index 71ee488..89e0ee3 100644 --- a/Submission/Makefile +++ b/Makefile @@ -10,9 +10,6 @@ all: StrList .PHONY: clean -test: test.o StrList.o - $(CC) $(CFLAGS) -o $@ $^ - StrList: $(TARGET_OBJECTS) $(CC) $(CFLAGS) -o $@ $^ @@ -20,4 +17,4 @@ StrList: $(TARGET_OBJECTS) $(CC) $(CFLAGS) -c $^ clean: - rm -f *.o StrList test *.gch \ No newline at end of file + rm -f *.o StrList *.gch *.h.gch \ No newline at end of file diff --git a/Submission/StrList.c b/StrList.c similarity index 100% rename from Submission/StrList.c rename to StrList.c diff --git a/Submission/StrList.h b/StrList.h similarity index 100% rename from Submission/StrList.h rename to StrList.h diff --git a/Submission/personal_test/output1.txt b/Submission/personal_test/output1.txt deleted file mode 100644 index 89f7a1d..0000000 --- a/Submission/personal_test/output1.txt +++ /dev/null @@ -1,8 +0,0 @@ -Grace Hopper coined "bug" for computer glitches. In 1947, she found a moth causing issues in Harvard's Mark II. -19 -false -Grace Hopper coined "bug" for glitches. In 1947, she found a moth causing issues in Harvard's Mark II. -85 -glitches. -Grace Hopper coined "bug" for computer glitches. In 1947, she found a moth causing issues in Harvard's Mark II. -II. Mark Harvard's in issues causing moth a found she 1947, In glitches. computer for "bug" coined Hopper Grace diff --git a/Submission/personal_test/output2.txt b/Submission/personal_test/output2.txt deleted file mode 100644 index 6234eca..0000000 --- a/Submission/personal_test/output2.txt +++ /dev/null @@ -1,8 +0,0 @@ -Alan Turing's Turing machine concept laid the foundation for modern computing. His work influenced the development of computers and algorithms. -20 -124 -1 -Alan Turing's Turing machine laid the foundation for modern computing. His work influenced the development of computers and algorithms. -Alan His Turing Turing's algorithms. and computers computing. development for foundation influenced laid machine modern of the the work -true - diff --git a/Submission/personal_test/test.c b/Submission/personal_test/test.c deleted file mode 100644 index a767cdc..0000000 --- a/Submission/personal_test/test.c +++ /dev/null @@ -1,356 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include "StrList.h" - -void test_StrList_alloc_free() { - // Test StrList_alloc and StrList_free - printf("Testing StrList_alloc and StrList_free:\n"); - StrList* list = StrList_alloc(); - if (list != NULL) { - printf("PASS: StrList_alloc returned a non-NULL pointer.\n"); - } else { - printf("FAIL: StrList_alloc returned a NULL pointer.\n"); - } - StrList_free(list); - printf("StrList_free called successfully.\n\n"); -} - -void test_StrList_size() { - // Test StrList_size - printf("Testing StrList_size:\n"); - StrList* list = StrList_alloc(); - size_t initialSize = StrList_size(list); - if (initialSize == 0) { - printf("PASS: Initial size is 0.\n"); - } else { - printf("FAIL: Initial size is not 0.\n"); - } - - StrList_insertLast(list, "Hello"); - StrList_insertLast(list, "World"); - size_t updatedSize = StrList_size(list); - if (updatedSize == 2) { - printf("PASS: Size after insertion is 2.\n"); - } else { - printf("FAIL: Size after insertion is not 2.\n"); - } - - StrList_free(list); - printf("\n"); -} - -void test_StrList_insertLast() { - // Test StrList_insertLast - printf("Testing StrList_insertLast:\n"); - StrList* list = StrList_alloc(); - StrList_insertLast(list, "Apple"); - StrList_insertLast(list, "Banana"); - StrList_insertLast(list, "Cherry"); - - printf("Elements after insertion:\n"); - StrList_print(list); - - StrList_free(list); - printf("\n"); -} - -void test_StrList_firstData() { - // Test StrList_firstData - printf("Testing StrList_firstData:\n"); - StrList* list = StrList_alloc(); - StrList_insertLast(list, "Apple"); - StrList_insertLast(list, "Banana"); - StrList_insertLast(list, "Cherry"); - - char* first = StrList_firstData(list); - if (first != NULL && strcmp(first, "Apple") == 0) { - printf("PASS: First element is 'Apple'.\n"); - } else { - printf("FAIL: First element is not 'Apple'.\n"); - } - - StrList_free(list); - printf("\n"); -} - -void test_StrList_print() { - // Test StrList_print - printf("Testing StrList_print:\n"); - StrList* list = StrList_alloc(); - StrList_insertLast(list, "Apple"); - StrList_insertLast(list, "Banana"); - StrList_insertLast(list, "Cherry"); - - printf("Elements in the list:\n"); - StrList_print(list); - - StrList_free(list); - printf("\n"); -} - -void test_StrList_count() { - // Test StrList_count - printf("Testing StrList_count:\n"); - StrList* list = StrList_alloc(); - StrList_insertLast(list, "Apple"); - StrList_insertLast(list, "Banana"); - StrList_insertLast(list, "Apple"); - StrList_insertLast(list, "Cherry"); - StrList_insertLast(list, "Apple"); - - int countApple = StrList_count(list, "Apple"); - if (countApple == 3) { - printf("PASS: Count of 'Apple' is 3.\n"); - } else { - printf("FAIL: Count of 'Apple' is not 3.\n"); - } - - int countBanana = StrList_count(list, "Banana"); - if (countBanana == 1) { - printf("PASS: Count of 'Banana' is 1.\n"); - } else { - printf("FAIL: Count of 'Banana' is not 1.\n"); - } - - int countOrange = StrList_count(list, "Orange"); - if (countOrange == 0) { - printf("PASS: Count of 'Orange' is 0.\n"); - } else { - printf("FAIL: Count of 'Orange' is not 0.\n"); - } - - StrList_free(list); - printf("\n"); -} - -void test_StrList_remove() { - // Test StrList_remove - printf("Testing StrList_remove:\n"); - StrList* list = StrList_alloc(); - StrList_insertLast(list, "Apple"); - StrList_insertLast(list, "Banana"); - StrList_insertLast(list, "Apple"); - StrList_insertLast(list, "Cherry"); - StrList_insertLast(list, "Apple"); - - printf("List before removal:\n"); - StrList_print(list); - - StrList_remove(list, "Apple"); - printf("List after removing 'Apple':\n"); - StrList_print(list); - - StrList_free(list); - printf("\n"); -} - -void test_StrList_removeAt() { - // Test StrList_removeAt - printf("Testing StrList_removeAt:\n"); - StrList* list = StrList_alloc(); - StrList_insertLast(list, "Apple"); - StrList_insertLast(list, "Banana"); - StrList_insertLast(list, "Cherry"); - StrList_insertLast(list, "Orange"); - - printf("List before removal at index 2:\n"); - StrList_print(list); - - StrList_removeAt(list, 2); - printf("List after removal at index 2:\n"); - StrList_print(list); - - StrList_removeAt(list, 0); - printf("List after removal at index 0:\n"); - StrList_print(list); - - StrList_removeAt(list, 1); - printf("List after removal at index 1:\n"); - StrList_print(list); - - // Test with empty list - StrList* emptyList = StrList_alloc(); - printf("Removing from an empty list:\n"); - StrList_removeAt(emptyList, 0); - printf("List after removal:\n"); - StrList_print(emptyList); - StrList_free(emptyList); - - // Test with NULL list - printf("Removing from a NULL list:\n"); - StrList_removeAt(NULL, 0); - printf("\n"); - - StrList_free(list); - printf("\n"); -} - -void test_StrList_isEqual() { - // Test StrList_isEqual - printf("Testing StrList_isEqual:\n"); - StrList* list1 = StrList_alloc(); - StrList_insertLast(list1, "Apple"); - StrList_insertLast(list1, "Banana"); - StrList_insertLast(list1, "Cherry"); - - StrList* list2 = StrList_alloc(); - StrList_insertLast(list2, "Apple"); - StrList_insertLast(list2, "Banana"); - StrList_insertLast(list2, "Cherry"); - - StrList* list3 = StrList_alloc(); - StrList_insertLast(list3, "Apple"); - StrList_insertLast(list3, "Banana"); - StrList_insertLast(list3, "Orange"); - - printf("List 1:\n"); - StrList_print(list1); - printf("List 2:\n"); - StrList_print(list2); - printf("List 3:\n"); - StrList_print(list3); - - int isEqual12 = StrList_isEqual(list1, list2); - if (isEqual12 == 1) { - printf("PASS: List 1 is equal to List 2.\n"); - } else { - printf("FAIL: List 1 is not equal to List 2.\n"); - } - - int isEqual13 = StrList_isEqual(list1, list3); - if (isEqual13 == 0) { - printf("PASS: List 1 is not equal to List 3.\n"); - } else { - printf("FAIL: List 1 is equal to List 3.\n"); - } - - // Test with empty lists - StrList* emptyList1 = StrList_alloc(); - StrList* emptyList2 = StrList_alloc(); - printf("Comparing empty lists:\n"); - int isEqualEmpty = StrList_isEqual(emptyList1, emptyList2); - if (isEqualEmpty == 1) { - printf("PASS: Empty lists are equal.\n"); - } else { - printf("FAIL: Empty lists are not equal.\n"); - } - StrList_free(emptyList1); - StrList_free(emptyList2); - - // Test with NULL lists - printf("Comparing NULL lists:\n"); - int isEqualNull = StrList_isEqual(NULL, NULL); - if (isEqualNull == 1) { - printf("PASS: NULL lists are equal.\n"); - } else { - printf("FAIL: NULL lists are not equal.\n"); - } - printf("\n"); - - StrList_free(list1); - StrList_free(list2); - StrList_free(list3); -} - -void test_StrList_clone() { - // Test StrList_clone - printf("Testing StrList_clone:\n"); - StrList* list = StrList_alloc(); - StrList_insertLast(list, "Apple"); - StrList_insertLast(list, "Banana"); - StrList_insertLast(list, "Cherry"); - - StrList* clonedList = StrList_clone(list); - - printf("Original list:\n"); - StrList_print(list); - printf("Cloned list:\n"); - StrList_print(clonedList); - - StrList_free(list); - StrList_free(clonedList); - printf("\n"); -} - -void test_StrList_reverse() { - // Test StrList_reverse - printf("Testing StrList_reverse:\n"); - StrList* list = StrList_alloc(); - StrList_insertLast(list, "Apple"); - StrList_insertLast(list, "Banana"); - StrList_insertLast(list, "Cherry"); - StrList_insertLast(list, "Orange"); - - printf("List before reverse:\n"); - StrList_print(list); - - StrList_reverse(list); - printf("List after reverse:\n"); - StrList_print(list); - - // Test with empty list - StrList* emptyList = StrList_alloc(); - printf("Reversing an empty list:\n"); - StrList_reverse(emptyList); - printf("List after reverse:\n"); - StrList_print(emptyList); - StrList_free(emptyList); - - // Test with NULL list - printf("Reversing a NULL list:\n"); - StrList_reverse(NULL); - printf("\n"); - - StrList_free(list); - printf("\n"); -} - -void test_StrList_sort() { - // Test StrList_sort - printf("Testing StrList_sort:\n"); - StrList* list = StrList_alloc(); - StrList_insertLast(list, "Banana"); - StrList_insertLast(list, "Cherry"); - StrList_insertLast(list, "Apple"); - StrList_insertLast(list, "Orange"); - - printf("List before sorting:\n"); - StrList_print(list); - - StrList_sort(list); - printf("List after sorting:\n"); - StrList_print(list); - - // Test with empty list - StrList* emptyList = StrList_alloc(); - printf("Sorting an empty list:\n"); - StrList_sort(emptyList); - printf("List after sorting:\n"); - StrList_print(emptyList); - StrList_free(emptyList); - - // Test with NULL list - printf("Sorting a NULL list:\n"); - StrList_sort(NULL); - printf("\n"); - - StrList_free(list); - printf("\n"); -} - -int main() { - test_StrList_alloc_free(); - test_StrList_size(); - test_StrList_insertLast(); - test_StrList_firstData(); - test_StrList_print(); - test_StrList_count(); - test_StrList_remove(); - test_StrList_removeAt(); - test_StrList_isEqual(); - test_StrList_clone(); - test_StrList_reverse(); - test_StrList_sort(); - - return 0; -}