ECE 209 / CSCI 255 Assignment 7D

Half an assignment.

Due date

This assignment must be submitted as a single file named RLexec.c for Assignment 7D of the ECE 209.602 section on UNCA moodle by 11:45 PM on 4 December.

Your program should be written in standard ANSI C.

Getting started

Surely you have read the RL Assignment overview by now.

Your task

Modification D is performed in the listByNameRL and cmpVarValue functions of RLexec.c. These modifications will allow you to use C's Quicksort function without having to ever learn what a partition operation is.

In part 1 of the modification, you are going to copy pointers to all the variables to an array.

    /* RL Modification D -- part 1:
     *
     * Write a doubly nested loop with some resemblence to the
     * one in listByNameRL (Modification C).  However, this time
     * fill sortedMess with pointers to *all* the variable nodes.
     *
     * 9 lines of code were removed here.
     */

In part 2, you are going to write one of those baffling comparison routines that must be passed to C's qsort functions.

    /* RL Modification D -- part 2:
     *
     * Var1 and Var2 point to two differenct variable nodes.
     * Write a section of code that returns:
     *   -1 -- if the value of Var1 is less than Var2
     *    1 -- if the value of Var1 is greater than Var2
     * Should the values of the two variables be the same
     * "break" the tie comparing the names of the variables
     * using strncmp.
     *
     * 9 lines of code were removed here.
     */

What should happen

Your program should now sort the variables by value.

Suggestions

The first part is pretty much a repeat of Assignment 7C except that you are storing rather than printing.

The second part requires some careful programming. However, the two casts at the beginning of cmpVarValue take care of the hard part.