Question: Haskell Points: 10 for public tests, 10 for private tests, 10 for code review. A comparator network can be represented as a list of pairs
Haskell
Points: 10 for public tests, 10 for private tests, 10 for code review. A comparator network can be represented as a list of pairs of numbers. Each pair (x, y) represents a comparator acting on the two wires numbered x and y. If the value on wire y is smaller than that on wire x, then the comparator swaps the values of the wires. Wire numbers start at 1. One executes a network by propagating an initial set of values on the wires through the various comparisons. The resulting values might or might not be sorted. An example is in sort1.txt: [(1,2),(3,4),(1,3),(2,4),(2,3)] This is the network in Figure 28.2 of the CLR chapter cited above. For this first part, your program needs to read a command-line that looks like Read filename where filename is the name of a file expected to contain a sorting network. For simplicity, it is ok if your program fails with a run-time exception if the file is not in the required format (of a list of pairs of integers), or does not exist. You should read in the network and then print it out again to a file called network.txt in a format where each comparison is on its own line, like this (for the network in sort1.txt): 1 -- 2 3 -- 4 1 -- 3 2 -- 4 2 -- 3 The comparisons should appear in the same order as in the input. There is a public test to check that the output for sort1.txt matches the example output in the file network1.txt. Please try to match the spacing (like one space on each side of the two dashes), for autograding purposes.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
