mirror of
https://github.com/ada-dmitry/prog.l_ada.git
synced 2026-09-24 09:10:14 +00:00
add Vova`s list
This commit is contained in:
Executable
BIN
Binary file not shown.
+7
-7
@@ -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
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user