hello everyone
how do i sort an array of 6 number with out using any type of sort and then printing the array sorted?
i have a source text file with this numbers {10 , 5 , 20 , 3 , 50 , 40}.
i copied the text file into an array and now i need to sort it with out using any type of sort and then print it to a new file sorted.
any suggestion? may using with min/max but i cant figure out how...
10x

>with out using any type of sort
Be more specific, please. You can't use an existing sort function? Any sorting algorithm at all?

nope.
i cant use any of that.
i need to find the lowest number, print it to the file, and then find the next lowest number.
but with out chaging the order of the array...

>but with out chaging the order of the array...
*sigh* You know, that's an important piece of information. Here's something to shut you up for a bit. It's a simple solution to your problem that you can use as a template for your own code:

#include <stdio.h>

int min_index ( int a[], int skip[], size_t n )
{
  int min = 0;
  size_t i;

  while ( min < n && skip[min] == 1 )
    ++min;

  for ( i = 1; i < n; i++ ) {
    if ( skip[i] != 1 && a[i] < a[min] )
      min = i;
  }

  return min;
}

int main ( void )
{
  int a[] = { 10, 5, 20, 3, 50, 40 };
  int skip[6] = {0};
  int i;

  for ( i = 0; i < 6; i++ ) {
    int min = min_index ( a, skip, 6 );

    printf ( "%d\n", a[min] );
    skip[min] = 1;
  }

  return 0;
}

thanx alot, but still one question
why is he writing (3 5 10 10 10 10) insted of (3 5 10 20 40 50)?

I forgot to add a step. It's fixed now.

wow.

now THAT was one helluva gift, serverdude.

you don't even know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.