C program below (sort) reads input from command line (array x) and it will gener
ID: 669984 • Letter: C
Question
C program below (sort) reads input from command line (array x) and it will generate output (array y) in sorted order. Note that the maximum number is 10. Please fill the insert function to complete the program. /* sort.c */ #include int x[ 10].y[10].num_inputs.num_y=0; void get_args(int ac,char *av) { int i; num_inputs = ac-1; for(i=0;i'=0;num_> '++) { insert(x(num_y)); } } Example: sort 6 3 8 9 5 1 Array y: First call to insert: 6 Second call to insert: 3 6 Third call to insert: 3 6 8 Forth call to insert: 36 8 9 Fifth call to insert: 3 5 6 8 9 Final call to insert: 1 3 5 6 8 9Explanation / Answer
void insert(int new_y){
y[num_y] = new_y;
for (i = num_y-1; i >= 0; i++){
if (y[i] > y[num_y])
i--;
else
break;
}
if (i > -1){
int temp = y[i];
y[i] = new_y;
y[num_y] = temp;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.