From: Florian Forster Date: Mon, 20 Dec 2010 08:35:59 +0000 (+0100) Subject: src/sn-oddevenmerge.c: Only output a merging network. X-Git-Tag: v1.0.0~15 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=dd547641d34a662ea0d38921955980d8d9f8bd3b;p=sort-networks.git src/sn-oddevenmerge.c: Only output a merging network. See sn-oddevensort for a generator for the odd-even _sorting_ network. --- diff --git a/src/sn-oddevenmerge.c b/src/sn-oddevenmerge.c index 18a5669..e4161be 100644 --- a/src/sn-oddevenmerge.c +++ b/src/sn-oddevenmerge.c @@ -33,30 +33,36 @@ int main (int argc, char **argv) { - sn_network_t *n; - size_t inputs_num; + sn_network_t *sn_left; + sn_network_t *sn_right; + sn_network_t *oem; + int inputs_left; + int inputs_right; - if (argc != 2) + if (argc != 3) { - printf ("Usage: %s \n", argv[0]); + printf ("Usage: %s \n", argv[0]); return (0); } - inputs_num = (size_t) atoi (argv[1]); - if (inputs_num < 2) + inputs_left = atoi (argv[1]); + inputs_right = atoi (argv[2]); + if ((inputs_left < 1) || (inputs_right < 1)) { - fprintf (stderr, "Invalid number of inputs: %zu\n", inputs_num); + fprintf (stderr, "Invalid number of inputs: %i/%i\n", + inputs_left, inputs_right); return (1); } - n = sn_network_create_odd_even_mergesort (inputs_num); - if (n == NULL) - { - printf ("n == NULL!\n"); - return (1); - } + sn_left = sn_network_create (inputs_left); + sn_right = sn_network_create (inputs_right); + oem = sn_network_combine_odd_even_merge (sn_left, sn_right); + + sn_network_write (oem, stdout); - sn_network_write (n, stdout); + sn_network_destroy (sn_left); + sn_network_destroy (sn_right); + sn_network_destroy (oem); return (0); } /* int main */