COM2067 Lab 7 Solved

Category: Tags: ,

Description

Rate this product

Write a program that sorts the given integer values. The number of values is not known in advance. Your program will output the sorted values and the structure of the tree using given output format. (Assume for this lab study, values are distinct). Use AVL tree in your program.

Input:

72 18 28 36 27 117 108 90 -1

Your output will be the sorted list of given numbers (In-order walk on AVL tree produce the sorted list).

18
27
28
36
72
90
108
117

Your program should also print the AVL tree in the following way (First number represents the value, second number displays the parent node and the third number shows the balance factor. B is used for balance factor, L represents left child and R represents right child).

28 (-1 B)
18 (28 L) (-1 B) 72 (28 R) (-1 B)
27 (18 R) (0 B) 36 (72 L) (0 B) 108 (72 R) (0 B) 90 (108 L) (0 B) 117 (108 R) (0 B)

Output:

18
27
28
36
72
90
108
117

28 (-1 B)
18 (28 L) (-1 B) 72 (28 R) (-1 B)
27 (18 R) (0 B) 36 (72 L) (0 B) 108 (72 R) (0 B) 90 (108 L) (0 B) 117 (108 R) (0 B)

  • Lab-7-wuohjq.zip