diff --git a/gen/Trees/appT b/gen/Trees/appT new file mode 100755 index 0000000..3c13e73 Binary files /dev/null and b/gen/Trees/appT differ diff --git a/gen/Trees/func.c b/gen/Trees/func.c index 78293bb..3bb7afa 100644 --- a/gen/Trees/func.c +++ b/gen/Trees/func.c @@ -62,13 +62,13 @@ tree *maxim(tree *root) tree *findForDel(tree *root) { - tree *p = root, *lef = NULL; // Если есть правое поддерево, то ищем минимальный элемент в этом поддереве - if (p -> right != NULL) - return minim(p -> right); - lef = p -> parent; - while ((lef != NULL) && (p == lef -> right)) + tree *rig = root, *lef = NULL; // Если есть правое поддерево, то ищем минимальный элемент в этом поддереве + if (rig -> right != NULL) + return minim(rig -> right); + lef = rig -> parent; + while ((lef != NULL) && (rig == lef -> right)) { - p = lef; + rig = lef; lef = lef -> parent; } return lef; @@ -77,7 +77,7 @@ tree *findForDel(tree *root) tree *del_node(tree *root, int field) { // Поиск удаляемого узла по ключу - tree *p = root, *lef = NULL, *tmp = NULL; + tree *rig = root, *lef = NULL, *tmp = NULL; lef = find_node(root, field); // 1 случай: у узла нет потомков if ((lef -> left == NULL) && (lef -> right == NULL)) diff --git a/gen/Trees/main.c b/gen/Trees/main.c index 6cbd9b8..0ad2ef0 100644 --- a/gen/Trees/main.c +++ b/gen/Trees/main.c @@ -2,6 +2,24 @@ #include #include "head.h" -int main(){ - return 126; +int main(int argc, char *argv[]){ + tree *root=NULL; + root = init_root(root, 65); + print_tree(root); + printf("\n"); + root=del_node(root, 65); + print_tree(root); + printf("\n"); + root = add_node(root, 70); + root = add_node(root, 66); + root = add_node(root, 68); + root = add_node(root, 71); + root = add_node(root, 67); + root = add_node(root, 72); + print_tree(root); + printf("\n"); + root = del_node(root, 66); + print_tree(root); + printf("\n"); + return 0; } \ No newline at end of file diff --git a/other/Vova/list/app b/other/Vova/list/app new file mode 100755 index 0000000..fbb3ce6 Binary files /dev/null and b/other/Vova/list/app differ diff --git a/other/Vova/list/fulfill.c b/other/Vova/list/fulfill.c new file mode 100755 index 0000000..4754418 --- /dev/null +++ b/other/Vova/list/fulfill.c @@ -0,0 +1,60 @@ +#include "head.h" + +int main(int argc, char *argv[]) +{ + printf("Hello! Let's begin\n"); + 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("No memory for you\n"); + exit(2); + } + n1 = add_tail(n1, "tail"); + + printf("First error\n"); + + int i; + for (i = 0; i < CO; i++) + { + char s[LEN]; + int m; + printf("Let it be\n"); + for (m = 0; m < LEN - 1; m++) + s[m] = 'V' + rand() % 2; + s[LEN - 1] = '\0'; + + n1 = add_tail(n1, s); + printf("10"); + for (m = 0; m < LEN - 1; m++) + { + s[m] = 'V' + rand() % 2; + printf("20"); + } + s[LEN - 1] = '\0'; + n2 = add_tail(n2, s); + } + + printf("Initial arrays:\n"); + node_print(n1); + printf("\n"); + node_print(n2); + + n3 = find_0(n1, n2); + + printf("\n"); + + printf("Final version:\n"); + node_print(n3); + + free(n1); + free(n2); + free(n3); + + printf("That's all for now\n"); + + return 0; +} \ No newline at end of file diff --git a/other/Vova/list/funcinst.c b/other/Vova/list/funcinst.c new file mode 100755 index 0000000..3e1e7c9 --- /dev/null +++ b/other/Vova/list/funcinst.c @@ -0,0 +1,106 @@ +#include "head.h" + +void node_print(Node *n) +{ + while (n != NULL) + { + printf("%s\n", n->name); + n = n->ne; + } +} + +int len(Node *n) +{ + int f = 0; + while (n != NULL) + { + f++; + n = n->ne; + } + return f; +} + +Node *add_tail(Node *n, char s[]) +{ + if (n == NULL) + { + if ((n = malloc(sizeof(Node))) == NULL) + { + printf("No memory for you\n"); + exit(1); + } + n->ne = NULL; + n->prv = NULL; + memcpy(n->name, s, LEN); + return n; + } + if (!strcmp(n->name, "\0")) + { + memcpy(n->name, s, LEN); + n->ne = NULL; + n->prv = NULL; + return n; + } + Node *res = n; + while (n->ne != NULL) + { + printf("%p\n", n); + n = n->ne; + } + Node *tmp = malloc(sizeof(Node)); + memcpy(tmp->name, s, LEN); + tmp->prv = n; + n->ne = tmp; + return res; +} + +Node get(Node *node, int n) +{ + int k; + for (k = 0; k < n; k++) + { + node = node->ne; + } + return *node; +} + +Node *find_0(Node *n1, Node *n2) +{ + int i, j, f = 0; + Node *res = NULL; + if ((res = malloc(sizeof(Node))) == NULL) + { + printf("No memory for you\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/other/Vova/list/head.h b/other/Vova/list/head.h new file mode 100755 index 0000000..da4d74a --- /dev/null +++ b/other/Vova/list/head.h @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +#define CO 3 +#define LEN 3 + +typedef struct Node +{ + char name[LEN]; + struct Node *ne; + struct Node *prv; +} Node; + +void node_print(Node *n); +Node *add_tail(Node *n, char s[]); +Node get(Node *node, int n); +Node *find_0(Node *n1, Node *n2); +int len(Node *n); \ No newline at end of file