Question: Write a C program that sorts the given integer values. The number of values is not known in advance. Your program will display the sorted
Write a C program that sorts the given integer values. The number of values is not known in advance. Your program will display the sorted values and the structure of the tree using the given output format. (For this assignment, assume that the values entered by the user differ from each other). Use the red-black tree in your program.
Input:
45
95
35
55
85
25
15
65
75
-1
Your output will be an ordered list of given numbers (in-order in the red-black tree creates the sorted list). Your program should also print the red-black tree as below (The first number represents the value, the letter next to the number indicates the color (R for red and B for black) and the number and letter in parentheses indicate the parent node. L represents the left child and R represents the right child. ). Empty nodes (leaf nodes) will not be printed.
Your output will be an ordered list of given numbers (in-order in the red-black tree creates the sorted list). Your program should also print the red-black tree as below (The first number represents the value, the letter next to the number indicates the color (R for red and B for black) and the number and letter in parentheses indicate the parent node. L represents the left child and R represents the right child. ). Empty nodes (leaf nodes) will not be printed.
45 B
25 B (45 L) 85 R (45 R)
15 R (25 L) 35 R (25 R) 65 B (85 L) 95 B (85 R)
55 R (65 L) 75 R (65 R)
Output:
15
25
35
45
55
65
75
85
95
45 B
25 B (45 L) 85 R (45 R)
15 R (25 L) 35 R (25 R) 65 B (85 L) 95 B (85 R)
55 R (65 L) 75 R (65 R)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
