From b4dbd2cfa724476162fa6d35941a5d7cdc9c9524 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Mon, 18 Feb 2019 08:10:10 -0500 Subject: Adds all assignments not previously in a git repo --- CS2501/sorting/sortAssignment1.c | 80 ++++++++++++++++++++++++++++++++++ CS2501/sorting/sortAssignment2.c | 94 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 CS2501/sorting/sortAssignment1.c create mode 100644 CS2501/sorting/sortAssignment2.c (limited to 'CS2501/sorting') diff --git a/CS2501/sorting/sortAssignment1.c b/CS2501/sorting/sortAssignment1.c new file mode 100644 index 0000000..1ff5662 --- /dev/null +++ b/CS2501/sorting/sortAssignment1.c @@ -0,0 +1,80 @@ +#include +#include +#include + + +printData(d,n) +int *d,n; +{ + int i; + for (i=0; i d[j]){ + d[i] = d[j]; + d[j] = tmp; + tmp = d[i]; + } + } + + } +} + +insertionSortDescending(d, n) +int *d, n; +{ + int i,j,tmp; + + for (i = 1; i < n; i++){ + for (j = i; d[j] > d[j-1] && j != 0; j--){ + tmp = d[j]; + d[j] = d[j-1]; + d[j-1] = tmp; + } + } +} + + + + +main(argc, argv, envp) +int argc; +char **argv, **envp; +{ + char buf[1024]; + int n, *data, i; + if (argc !=2 ) { + printf("usage: sortAssignment1 #elements\n"); + exit(1); + } + + n = atoi(argv[1]); + data = calloc(n, sizeof(int)); + for (i=0; i +#include +#include + + +printData(d,n) +int *d,n; +{ + int i; + for (i=0; i= 0; i--) { + if(n2 == 0) + d[i] = tmp1[--n1]; + + else if (n1 == 0) + d[i] = tmp2[--n2]; + else + d[i] = (tmp1[n1-1] < tmp2[n2-1]) ? tmp1[--n1] : tmp2[--n2]; + } + printf("\n"); + free(tmp1); + free(tmp2); + return; +} + +heapSort(d, n) +int *d, n; +{ +} + + + + +main(argc, argv, envp) +int argc; +char **argv, **envp; +{ + char buf[1024]; + int n, *data, i; + if (argc !=2 ) { + printf("usage: sortAssignment1 #elements\n"); + exit(1); + } + + n = atoi(argv[1]); + data = calloc(n, sizeof(int)); + for (i=0; i