Question: I have the following C code that is functioning. It prints out the start status of the array and the ending status. I need it

I have the following C code that is functioning. It prints out the start status of the array and the ending status. I need it to print a status after every swap. I will provide an example of what I have and also of what I need it to do. I think it is an easy fix but I am stumped

#include #define MAX 9

void printvalues(); void sort(); void swap(int*, int*); int values[] = {7,3,9,4,6,1,2,8,5};

void printvalues() { int i = 0; for (i=0; values[i] != '\0'; i++) { printf("%d", values[i]); } printf(" "); }

void swap(int* x, int* y) { int var; var = *x; *x = *y; *y = var; }

void sort() { int i = 0; int j = 0; for (i=0; values[i] != '\0'; i++) { for(j=0; values[j+1] != '\0'; j++) { if (values[j] > values[j+1]) { swap(&values[j], &values[j+1]); } } } }

int main() { printf("Before "); printvalues(); sort(); printf("After "); printvalues(); return 0; }

This is what I have currently:

I have the following C code that is functioning. It prints out

This is what i need:

the start status of the array and the ending status. I need

Before 739461285 After 123456789 Before: [7 3 9 4 6 1 2 85] [3 7 9 4 6 12 8 5] [3 7 4 9 612 85] [3 7 4 6 9 12 85] [3 7 4 6 19 285] [3 7 4 6 1 29 85] [3 74 61 28 95] [3 7 4 6 12 8 5 9 ] [3 4 7 6 12 8 59 ] [3 4 6 7 1 2 8 59] [3 4 6 17 2859] [3 4 6 1 27 859] [3 4 5 1 2 7 5 8 9 ] [3 4 16 2 7 5 8 9 ] [3 4 1 2 6 7 5 8 9 ] [3 4 1 2 6 5 7 8 9 ] [3 1 4 2 6 5 7 8 9 ] [3 1 2 4 6 5 7 8 9 ] [3 1 2 4 5 6 7 8 9 1 [1 3 2 4 5 6 7 8 9 ] [1 2 3 4 5 6 7 8 9 ] After: [1 2 3 4 5 6 7 8 9 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!