   Next: Input and Output (I/O) Up: Dynamic Memory Allocation Previous: Linked Lists

# Exercises

1. Write a program that reads a number that says how many integer numbers are to be stored in an array, creates an array to fit the exact size of the data and then reads in that many numbers into the array.

">

2. Write a program to implement the linked list as described in the notes above.

">

3. Write a program to sort a sequence of numbers using a binary tree (Using Pointers). A binary tree is a tree structure with only two (possible) branches from each node (Fig. ). Each branch then represents a false or true decision. To sort numbers simply assign the left branch to take numbers less than the node number and the right branch any other number (greater than or equal to). To obtain a sorted list simply search the tree in a depth first fashion.  Fig. Example of a binary tree sort

Your program should: Create a binary tree structure. Create routines for loading the tree appropriately. Read in integer numbers terminated by a zero. Sort numbers into numeric ascending order. Print out the resulting ordered values, printing ten numbers per line as far as possible.

Typical output should be

```
The sorted values are:
2  4  6  6  7  9 10 11 11 11
15 16 17 18 20 20 21 21 23 24
27 28 29 30```

">

(unit6:pointers:bin)

Dave.Marshall@cm.cf.ac.uk
Fri May 20 13:40:49 BST 1994