www.delorie.com/gnu/docs/avl/libavl_81.html | search |
Buy GNU books! | |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
We need code to generate a random permutation of numbers to order insertion and deletion of items. We will support some other orders besides random permutation as well for completeness and to allow for overflow testing. Here is the complete list:
The code to actually generate these orderings is left to the exercises.
Exercises:
1. Write a function to generate a random permutation of the n ints between 0 and n - 1 into a provided array. [answer]
*2. Write a function to generate an ordering of ints that, when inserted into a binary tree, produces a balanced tree of the integers from min to max inclusive. (Hint: what kind of recursive traversal makes this easy?) [answer]
3. Write one function to generate an insertion order of n integers into a provided array based on an enum insert_order and the functions written in the previous two exercises. Write a second function to generate a deletion order using similar parameters plus the order of insertion. [answer]
*4. By default, the C random number generator produces the same sequence every time the program is run. In order to generate different sequences, it has to be "seeded" using srand() with a unique value. Write a function to select a random number seed based on the current time. [answer]
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
webmaster | delorie software privacy |
Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |