diff --git a/Hayet_Classwork/list b/Hayet_Classwork/list new file mode 100755 index 0000000..30ad377 Binary files /dev/null and b/Hayet_Classwork/list differ diff --git a/Hayet_Classwork/list.c b/Hayet_Classwork/list.c new file mode 100644 index 0000000..66643bb --- /dev/null +++ b/Hayet_Classwork/list.c @@ -0,0 +1,52 @@ +#include +#include +#include + +typedef struct node +{ + int number; + struct node *next; +} node; + +int main(void) +{ + node *list = NULL; + // Create list + for (int i = 0; i < 3; i++) + { + int x = get_int("Number: "); + + node *n = malloc(sizeof(node)); + + if (n == NULL) + { + return 1; + } + + n->number = x; + n->next = list; + + list = n; + } + + + // Print list + node *ptr = list; + + while (ptr != NULL) + { + printf("%i\n", ptr->number); + ptr = ptr->next; + } + + + // Free memory + ptr = list; + + while (ptr != NULL) + { + node *tmp = ptr; + ptr = ptr->next; + free(tmp); + } +} diff --git a/Hayet_Classwork/list_buggy b/Hayet_Classwork/list_buggy new file mode 100755 index 0000000..ec77f4a Binary files /dev/null and b/Hayet_Classwork/list_buggy differ diff --git a/Hayet_Classwork/list_buggy.c b/Hayet_Classwork/list_buggy.c new file mode 100644 index 0000000..fe8ff58 --- /dev/null +++ b/Hayet_Classwork/list_buggy.c @@ -0,0 +1,47 @@ +#include +#include +#include + +typedef struct node +{ + int number; + struct node *next; +} node; + +int main(void) +{ + node *list = NULL; + // Create List + for (int i = 0; i < 3; i++) + { + int x = get_int("Number: "); + + node *n = malloc(sizeof(node)); + n->number = x; + n->next = list; + + list = n; + + if (n == NULL) + { + printf("Malloc failed. \n"); + return 1; + + } + + for (node *ptr = list; ptr !=NULL; ptr = ptr->next) + { + printf("%i\n", ptr->number); + } + + node *ptr = list; + while(ptr !=NULL) + { + node *tmp = ptr; + ptr = ptr->next; + free(tmp); + } + + } + +} diff --git a/Python/__pycache__/copy.cpython-312.pyc b/Python/__pycache__/copy.cpython-312.pyc new file mode 100644 index 0000000..a9ba12e Binary files /dev/null and b/Python/__pycache__/copy.cpython-312.pyc differ diff --git a/Python/agree.py b/Python/agree.py new file mode 100644 index 0000000..41fb8fb --- /dev/null +++ b/Python/agree.py @@ -0,0 +1,9 @@ +s = input("Do you agree? ") +s = s.lower() + +if s in ["y", "yes"]: + + print("Agreed.") + +else: + print("Not Agreed.") diff --git a/Python/blur.py b/Python/blur.py new file mode 100644 index 0000000..8ac9f39 --- /dev/null +++ b/Python/blur.py @@ -0,0 +1,5 @@ +from PIL import Image, ImageFilter + +before = Image.open("bridge.bmp") +after = before.filter(ImageFilter.BoxBlur(10)) +after.safe("out.bmp") diff --git a/Python/cat.py b/Python/cat.py new file mode 100644 index 0000000..ba4ce7e --- /dev/null +++ b/Python/cat.py @@ -0,0 +1,3 @@ +for _ i in range(3): + print("Meow") + diff --git a/Python/compare.py b/Python/compare.py new file mode 100644 index 0000000..c34c63a --- /dev/null +++ b/Python/compare.py @@ -0,0 +1,8 @@ +s = input("s: ") +t = input ("t: ") + +if s == t: + print("Same") +else: + print("Different") + diff --git a/Python/copy.py b/Python/copy.py new file mode 100644 index 0000000..1473be7 --- /dev/null +++ b/Python/copy.py @@ -0,0 +1,8 @@ +s = input("s: ") + +t = s.capitalize() + +print(f"s: {s}") +print(f"t: {t}") + + diff --git a/Python/dictionary.py b/Python/dictionary.py new file mode 100644 index 0000000..cabc1db --- /dev/null +++ b/Python/dictionary.py @@ -0,0 +1,15 @@ +words = set() + +def check(word): + return word.lower() in words + +def load(dictionary): + with open(dictionary) as file: + words.update(file.read().splitlines()) + return True + + def size(): + return len(words) + + def unload(): + return True diff --git a/Python/hello.py b/Python/hello.py new file mode 100644 index 0000000..94e67f0 --- /dev/null +++ b/Python/hello.py @@ -0,0 +1 @@ +print ("Hello World") diff --git a/Python/mario.py b/Python/mario.py new file mode 100644 index 0000000..91a0363 --- /dev/null +++ b/Python/mario.py @@ -0,0 +1,12 @@ +while True: + n = int(input("Height: ")) + if n > 0: + break + + for i in range(n): + print("#") + + +for i in range(4): + print("?", end ="") + print() diff --git a/Python/uppercase.py b/Python/uppercase.py new file mode 100644 index 0000000..187c7cb --- /dev/null +++ b/Python/uppercase.py @@ -0,0 +1,6 @@ +before = input("Before: ") +print("After: ", end="") +for c in before: + print(c.upper(), end="") + +print() diff --git a/hash b/hash new file mode 100755 index 0000000..725379e Binary files /dev/null and b/hash differ diff --git a/hash.c b/hash.c new file mode 100644 index 0000000..facdfa8 --- /dev/null +++ b/hash.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +int hash(char *word); + +int main(void) +{ + char *word= get_string("Word: "); + printf("Hash value: %i\n", hash(word)); +} + +int hash(char *word) +{ + if (word == NULL || strlen(word) == 0) + { + return -1; + } + char c = word[0]; + if (isalpha(c)) + { + c = toupper(c); + return c -'A'; + } + return -1; +} + diff --git a/list b/list new file mode 100755 index 0000000..41c415e Binary files /dev/null and b/list differ diff --git a/list.c b/list.c new file mode 100644 index 0000000..9820dea --- /dev/null +++ b/list.c @@ -0,0 +1,43 @@ +#include +#include + +int main(void) +{ + int *list = malloc(3 * sizeof(int)); + if(list ==NULL) + + list[0] = 1; + list[1] = 2; + list[2] = 3; + + // Time passes + + int *tmp = realloc(list, 4 * sizeof(int)); + + if (tmp == NULL) + { + free(list); + return 1; + } + + // Copy old list into new list + for (int i = 0; i <3; i++) + { + tmp[i] = list[i]; + } + tmp[3] = 4; + + // Free original list + free(list); + + list = tmp; + + for (int i = 0; i <3; i++) + { + printf("%i\n", list[i]); + } + free(list); + return 0; +} + + diff --git a/list1.c b/list1.c new file mode 100644 index 0000000..a4ddc17 --- /dev/null +++ b/list1.c @@ -0,0 +1,39 @@ +#include +#include +#include + +typedef struct node +{ + int number; + struct node *next; +} node; + +int main(void) +{ + node *list = NULL; + + for (int = 0; i < 3; i++) + { + node *n = malloc(sizeof(node)); + if (n == NULL) + {return 1;} + // n-> = NULL; + (*n).number = get_int("Number: "); + // n-> = NULL; + (*)n.next = NULL; + + // Prepend node to list + n->next = list + list =n; + } + + // Print Numbers + node *ptr = list; + while (ptr !=NULL) + { + printf("%i\n", ptr->number); + } + return 0; +} + +