/* C program to do Bubblesort, with function to switch array elements. Lin Jensen January 2013 for csc116 class */ #include #include // for malloc,atoi, free #define LEN 10 int test[LEN] = {1,3,2,8,4,5,9,1,42,33}; int inorder(int a[], int length) // same as int *a, a is pointer to an array /* switches any successive elements that are out of order returns true (1) if no switches made */ { int inorder=true; for (int i=0; i two) { *a = two; *(a+1) = one; inorder = false; } } return inorder; } int main(int argc, char* argv[]) { int len; int* array = test; if (argc > 2) { /* get command line arguments as test array, separate by spaces For example: bubble 65 3 42 argc is number of arguments argv[] is an array of strings, the command line separated by spaces */ len = argc-1; // note: argv[0] is name of program array = (int *)malloc(len*sizeof(int)); // dynamic array space for (int i=0; i2) free(array); // free dynamically allocated space return 0; }