add Vova`s list

This commit is contained in:
ada-dmitry
2023-05-09 17:49:42 +03:00
parent 31a9fdc3f7
commit 875630a713
7 changed files with 213 additions and 9 deletions
Executable
BIN
View File
Binary file not shown.
+7 -7
View File
@@ -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))
+20 -2
View File
@@ -2,6 +2,24 @@
#include <stdio.h>
#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;
}