-
Notifications
You must be signed in to change notification settings - Fork 0
/
testavl.c
69 lines (65 loc) · 1.56 KB
/
testavl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<stdio.h>
#include<stdlib.h>
#include"bintree.h"
#include"avl.h"
void test_deletion(struct AVL *A, int x)
{
printf("\n----------------\n");
printf("Deletion of %d:\n", x);
avl_delete_elm(A, x);
avl_ugly_print(A);
}
void test_insertion(struct AVL *A, int x)
{
printf("\n----------------\n");
printf("Insertion of %d:\n", x);
avl_insert(A, x);
avl_ugly_print(A);
}
void avl_test(struct AVL *A)
{
printf("\n----------------\n");
avl_ugly_print(A);
avl_breadth_first_print(A);
printf("max: %d\n", *avl_max(A)->data);
printf("min: %d\n", *avl_min(A)->data);
printf("size: %d\nheight: %d\nwidth: %d\n", avl_size(A), avl_height(A), avl_width(A));
struct AVL *F1 = avl_search(A, 1);
if(F1)
printf("1 is present in the tree\n");
else
printf("1 is not present in the tree\n\n");
struct AVL *F9 = avl_search(A, 9);
if(F9)
printf("9 is present in the tree\n");
else
printf("9 is not present in the tree\n");
}
int main()
{
struct AVL *A = avl_init(4);
avl_ugly_print(A);
test_insertion(A, 10);
test_insertion(A, 12);
test_insertion(A, 15);
test_insertion(A, 20);
test_insertion(A, 26);
test_insertion(A, 31);
test_insertion(A, 34);
test_insertion(A, 38);
test_insertion(A, 43);
test_insertion(A, 49);
test_insertion(A, 51);
test_insertion(A, 54);
test_insertion(A, 60);
test_insertion(A, 62);
test_insertion(A, 65);
test_insertion(A, 68);
test_insertion(A, 74);
test_insertion(A, 80);
test_insertion(A, 84);
test_insertion(A, 37);
test_deletion(A, 49);
avl_balance_print(A);
avl_delete(A);
}