diff --git a/Home/PL/HW/Hanoi Towers/func.c b/Home/PL/HW/Hanoi Towers/func.c new file mode 100644 index 0000000..e69de29 diff --git a/Home/PL/HW/Hanoi Towers/head.h b/Home/PL/HW/Hanoi Towers/head.h new file mode 100644 index 0000000..e69de29 diff --git a/Home/PL/HW/Hanoi Towers/main.c b/Home/PL/HW/Hanoi Towers/main.c new file mode 100644 index 0000000..e69de29 diff --git a/Home/PL/HW/Stack Calculator/calk.exe b/Home/PL/HW/Stack Calculator/calk.exe new file mode 100644 index 0000000..6ee7812 Binary files /dev/null and b/Home/PL/HW/Stack Calculator/calk.exe differ diff --git a/Home/PL/HW/Stack Calculator/head.h b/Home/PL/HW/Stack Calculator/head.h new file mode 100644 index 0000000..b947d0f --- /dev/null +++ b/Home/PL/HW/Stack Calculator/head.h @@ -0,0 +1,17 @@ +#include +#include +#include +#include +#include + +typedef struct node { + int x; + struct node* next; +}Plate; + +void print_plates(Plate* plates); +Plate* push(Plate* plates, int x); +Plate* remove_plate(Plate* plates); +int pop(Plate** plates); +int len(Plate* plates); +int isnm(char *str); \ No newline at end of file diff --git a/Home/PL/HW/Stack Calculator/lib.c b/Home/PL/HW/Stack Calculator/lib.c new file mode 100644 index 0000000..b39db14 --- /dev/null +++ b/Home/PL/HW/Stack Calculator/lib.c @@ -0,0 +1,74 @@ +#include "head.h" + +void print_plates(Plate *plates) +{ + if (plates == NULL) + { + printf("[%p]\n", plates); + return; + } + while(plates){ + printf("[%14p]->[%14p] ", plates, plates->next); + printf("data: [%4d]\n", plates->x); + plates = plates->next; + } + printf("-------------\n"); +} + +Plate* push(Plate* plates, int d){ + Plate *temp = NULL; + if((temp=malloc(sizeof(Plate)))==NULL){ + perror("malloc:NULL"); + exit(2); + } + temp->x = d; + if(plates==NULL) temp->next=NULL; + else{ + temp->next=plates; + } + return temp; +} + +Plate* del_head(Plate* plates){ + Plate *temp=plates; + if(plates==NULL) return NULL; + if(plates->next==NULL){ + free(plates); + return NULL; + } + plates = plates->next; + free(temp); + return plates; +} + +int len(Plate* plates){ + int ans = 0; + Plate *temp = plates; + if(plates==NULL) return 0; + while(temp){ + ans++; + temp=temp->next; + } + return ans; +} + +int pop(Plate** plates){ + int i; + if(*plates==NULL){ + printf("Error"); + exit(4); + } + i = (*plates)->x; + *plates = del_head(*plates); + return i; +} + +int isnm(char *str){ + int i = 0, n = strlen(str); + for(i=0; iname); + n = n->next; + } +} + +Node* add_tail(Node* n, char s[]) { + if (n == NULL) { + if ((n = malloc(sizeof(Node))) == NULL) { + printf("could not malloc\n"); + exit(1); + } + n->next = NULL; + n->prev = NULL; + memcpy(n->name, s, LEN); + return n; + } + if (!strcmp(n->name, "\0")) { + memcpy(n->name, s, LEN); + n->next = NULL; + n->prev = NULL; + return n; + } + + Node* res = n; + while (n->next != NULL) n = n->next; + + Node* tmp = malloc(sizeof(Node)); + memcpy(tmp->name, s, LEN); + tmp->prev = n; + n->next = tmp; + return res; +} + +Node get(Node* node, int n) { + int i; + for (i = 0; i < n; i++) { + node = node->next; + } + return *node; +} + +int len(Node* n) { + int res = 0; + while (n != NULL) { + res++; + n = n->next; + } + return res; +} + +Node* xor_find(Node* n1, Node* n2) { + int i, j, f = 0; + Node* res = NULL; + if ((res = malloc(sizeof(Node))) == NULL) { + printf("could not malloc\n"); + exit(3); + } + + for (i = 0; i < len(n1); i++) { + for (j = 0; j < len(n2); j++) { + if (strcmp(get(n1, i).name, get(n2, j).name) == 0) { + f = 1; + } + } + if (f == 0) + res = add_tail(res, get(n1, i).name); + f = 0; + } + + for (i = 0; i < len(n2); i++) { + for (j = 0; j < len(n1); j++) { + if (strcmp(get(n2, i).name, get(n1, j).name) == 0) { + f = 1; + } + } + if (f == 0) + res = add_tail(res, get(n2, i).name); + f = 0; + } + + return res; +} \ No newline at end of file diff --git a/Home/PL/HW/array_xor/gen.c b/Home/PL/HW/array_xor/gen.c new file mode 100644 index 0000000..e5be38c --- /dev/null +++ b/Home/PL/HW/array_xor/gen.c @@ -0,0 +1,46 @@ +#include "header.h" + + +int main(int argc, char* argv[]) { + srand(time(0)); + Node* n1 = NULL; + Node* n2 = NULL; + Node* n3 = NULL; + if ((n1 = malloc(sizeof(Node))) == NULL || (n2 = malloc(sizeof(Node))) == NULL || (n3 = malloc(sizeof(Node))) == NULL) { + printf("could not malloc\n"); + exit(2); + } + + int i; + for (i = 0; i < COUNT; i++) { + char s[LEN]; + int j; + + for (j = 0; j < LEN - 1; j++) + s[j] = 'a' + rand() % 2; + s[LEN - 1] = '\0'; + + n1 = add_tail(n1, s); + + for (j = 0; j < LEN - 1; j++) + s[j]= 'a' + rand() % 2; + s[LEN - 1] = '\0'; + n2 = add_tail(n2, s); + } + + printf("Source arrays:\n"); + node_print(n1); + printf("\n"); + node_print(n2); + + n3 = xor_find(n1, n2); + + printf("\nFinal array:\n"); + node_print(n3); + + free(n1); + free(n2); + free(n3); + + return 0; +} \ No newline at end of file diff --git a/Home/PL/HW/array_xor/header.h b/Home/PL/HW/array_xor/header.h new file mode 100644 index 0000000..9b8f564 --- /dev/null +++ b/Home/PL/HW/array_xor/header.h @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +#define COUNT 3 +#define LEN 3 + +typedef struct Node { + char name[LEN]; + struct Node* next; + struct Node* prev; +} Node; + +void node_print(Node* n); +Node* add_tail(Node* n, char s[]); +Node get(Node* node, int n); +Node* xor_find(Node* n1, Node* n2); +int len(Node* n); \ No newline at end of file diff --git a/Home/PL/HW/array_xor/xor_array.exe b/Home/PL/HW/array_xor/xor_array.exe new file mode 100644 index 0000000..f051163 Binary files /dev/null and b/Home/PL/HW/array_xor/xor_array.exe differ diff --git a/Home/PL/Old/output/DZSort.exe b/Home/PL/Old/output/DZSort.exe new file mode 100644 index 0000000..7998fde Binary files /dev/null and b/Home/PL/Old/output/DZSort.exe differ