I have tried that already.
Code:
void
sort(int values[], int n)
{
// TODO: implement an O(n^2) sort
for(int i=n-2;i>0;i--) {
for(int j=0;j<i;j++) {
if(values[j]>values[j+1]) {
int tempholder=values[j+1];
values[j+1]=values[j];
values[j]=tempholder;
}
printf("%d\n",values[j]);
}
}
return;
}
Output
9158
17767
18547
39017
23807
37962
22764
7977
31949
22714
55211
9158
17767
18547
23807
37962
22764
7977
31949
22714
39017
9158
17767
18547
23807
22764
7977
31949
22714
37962
9158
17767
18547
22764
7977
23807
22714
31949
9158
17767
18547
7977
22764
22714
23807
9158
17767
7977
18547
22714
22764
9158
7977
17767
18547
22714
7977
9158
17767
18547
7977
9158
17767
7977
9158
7977
AND
Code:
void
sort(int values[], int n)
{
// TODO: implement an O(n^2) sort
for(int i=n-2;i>0;i--) {
for(int j=0;j<i;j++) {
if(values[j]>values[j+1]) {
int tempholder=values[j+1];
values[j+1]=values[j];
values[j]=tempholder;
}
}
printf("%d\n",values[j]);
}
return;
}
ERROR
make find
gcc -ggdb -std=c99 -Wall -Werror -o find find.c helpers.c -lcs50 -lm
helpers.c: In function 'sort':
helpers.c:46:26: error: 'j' undeclared (first use in this function)
helpers.c:46:26: note: each undeclared identifier is reported only once for each function it appears in
make: *** [find] Error 1