CSE 2320 Section 060/061 Spring 1999

Program 2

Due: March 9, 1999, 1pm (March 10, 1999, 5:00pm for -10%)

For this program you will use sorted doubly-linked lists with sentinels to represent sets of positive integers and support the set operations: union, intersection and difference. As usual, you cannot use global variables. Specifically,

1.
Define a data structure for the sorted doubly-linked list with sentinel. Implement procedures for list allocation, deallocation, insertion, deletion, search and print. All references to ``set'' below imply the use of a sorted doubly-linked list with sentinel to represent the set.

2.
Implement the set operations union(S1,S2), intersection(S1,S2) and difference(S1,S2). Each of these operations creates and returns a new set which is the result of the appropriate set operation. Union returns the set of unique elements in either S1 or S2. Intersection returns the set of unique elements in both S1 and S2. Difference returns the set of elements in S1 that are not in S2.

3.
Your main program will read commands from a file whose name is given as the first argument to your executable. The syntax of the possible commands are shown in the following table. Set identifiers are of the form Sn, where n is a single digit (0-9). You may assume these ten sets are initially the empty. Symbols within commands are separated by a single space.

 Command Explanation assign Sn = { } Create a new set containing the positive integers and assign it to the set Sn. You may assume the integers are unique and less than 1000. assign Sn = Sn U Sn Create a new set that is the union of the second and third set and assign it to the first set. assign Sn = Sn & Sn Create a new set that is the intersection of the second and third set and assign it to the first set. assign Sn = Sn - Sn Create a new set that is the difference between the second and third set and assign it to the first set. print Sn Print the elements of the set in order in the same format as the first set command above.

In the assign commands, if the first set Sn is already defined, this existing set should first be deallocated. All dynamically allocated memory should be deallocated before your program exits.

Your main program should output each command read in with a preceding `> '. Your program should also print ``okay'' on a separate line after each assign command. Your program should print the elements of the set after each print command. See the files pgm2in and pgm2out in the class directory on omega for an example.

4.
Be sure to properly document your source code, as described in Program 1. After ensuring that your program compiles and executes correctly on the omega machine, run the program /public/cse/2320-061/handin2 to electronically hand in your source file. All source code must be in one file (i.e., no separate .h and .c files).