for(fill = 0; fill < (m-1); ++fill)
{
if(atomic_num[index_of_min] <= atomic_num[fill])
{
temp = atomic_num[index_of_min];
atomic_num[index_of_min] = atomic_num[fill];
atomic_num[fill] = temp;
}
++index_of_min;
}
for(j = 0; j < (m-1); j++)
fprintf(outp,"%d\n", atomic_num[j]);
It looks to me that you were trying to implement a bubble sort.
For that you need two index variables and two loops.
/* indexes for loops */
int a, b;
/* How many elements atomic_num has? */
int size = sizeof atomic_num / sizeof ( int );
/* temporal storage */
int temp;
for ( a = 0; a < size - 1; a++ )
{
for ( b = a + 1; b < size; b++ )
{
if ( atomic_num[a] > atomic_num[b] )
{
temp = atomic_num[a];
atomic_num[a] = atomic_num[b];
atomic_num[b] = temp;
}
}
/* printf( "%d\n", atomic_num[a] ); uncomment for displaying */
}
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
You could use a struct, or if the idea is too abstract for you, toy with the idea of parallel arrays, like you said.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439