import java.util.ArrayList; import java.util.Scanner; /** * Satisfies Problem 19.a.ii of Homework 1. Quoting from the assignment: *

* Reads a graphical representation of a comparator network on standard * input and produces the corresponding linear representation on * standard output, with the following additional constraints: * Each line of output, except the last, contains exactly 10 * integers. There is exactly one space following each integer in * the output, unless that integer is the last one on a line, in * which case the space is replaced by a single newline * character. * @author Ed Ropple */ public class CnetGraToLinMain { /** * Entry method of cnet-gra-to-lin. Accepts input and passes to cnetlib's * shared functions in order to return a list of ComparatorPairs, which are * then sent to standard output. * * @param args The command line arguments for the program. Are ignored * by this program. */ public static void main(String[] args) { ArrayList input = new ArrayList(); System.out.println("Enter below the graphical representation of the"); System.out.println("sorting network you want to parse back into a"); System.out.println("list form. Unlike cnet-lin-to-gra, whitespace"); System.out.println("matters, though blank lines will be ignored."); System.out.println("Enter an X on a blank line to terminate input."); System.out.println(); Boolean breakLoop = false; Scanner s = new Scanner(System.in); // read from stdin, emerge on X or x while (breakLoop == false) { System.out.print("> "); String foo = s.nextLine().trim(); if (foo.length() < 1) continue; if (foo.charAt(0) == 'X' || foo.charAt(0) == 'x') { breakLoop = true; continue; } else { input.add(foo); } } ArrayList output = Functions.outputComparatorList(input); System.out.println(); System.out.println(Functions.makeCanonicalLinearOutput(output)); System.exit(0); } }