This assignment uses Fortran restricted to the constructs in Fortran-II.
Fortran does not allow recursion. However, the g77 compiler allows
indirect recursion, which you may use if you must (you get more points if
you can avoid recursion). You may use logical IF, but you
must not use any form of IF that includes THEN.
You may use GOTO, of course.
It isn't very pleasant to represent linked structures in Fortran. You can use an array, where the index of the array is used instead of a pointer to refer to an element. You can represent a set of instances of a C struct or Pascal record in Fortran by building a separate, parallel array for every field; all arrays have the same set of indices.
Write a program in Fortran that (1) reads an integer, which we call nodeCount, then (2) reads nodeCount integers (one per line), inserting them one by one into an initially empty sorted binary tree, resolving ties by moving the right, then (3) prints the tree in preorder, one value per line, then (4) reads an integer, which we call probeCount, then (5) reads probeCount integers, and for each one, prints the integer and either "yes" or "no", depending on whether the integer is present in the tree. You may assume that the input data are well formed (there are enough integers, for example) and that nodeCount is not higher than 1000.
Test your program both on your own data and on the data in
http://www.cs.uky.edu/~raphael/courses/CS450/asg.fortran.data.
The Fortran you will use is called g77. It is available both in the
Multilab and in the CSLab. It is a traditional compiler, which means you
should use a text editor (like vi) to create your program in a file,
whose name must end in .f. Then you invoke the compiler as follows:
g77 -g -Wall filename.f -o filenameThe
-g flag causes the compiler to place extra information in the
output file that assists you in debugging later.
The -Wall flag tells the compiler to warn you about any apparent
programming errors, even those that don't prevent correct compilation.
You then invoke the program itself as
filenameYou may use the
gdb debugger if you need:
gdb filenameYou can give the debugger the
help command to see what it can do for you.
This assignment is due at the start of class time on the day indicated
in the syllabus. See the syllabus for the late policy. Submit the assignment
by email to raphael @cs.uky.edu.