title: Using selection sort with array of pointers
body: <p>I am currently trying to sort an array of pointers using selection sort, but with no success. I need to sort an array of int values with only pointers. I have already stored values in the array, and only thing left to do is to sort these values.  </p>
  
  <p>Here is my code:</p>
  
  <pre><code>void fill_rand_ver2(int *pointer, int size)
  {
  int randNbr;
  int *i;
  
  for(i = pointer; i &lt; (pointer + size); i++)
  {
      randNbr = (rand()%10)+1;
      *i = randNbr;
  }
  }
  
  // sort array with help of selection sort using pointer
  void sort_ver2(int *pointer, int size)
  {
  int *i, *j, swap;
  
  for(i = pointer; i &lt; (pointer + size); i++)
  {
      for(j = i + 1; j &lt; (pointer + size); j++)
      {
          if(*j &lt; *i)
          {
              swap = *i;
              *i = *j;
              *j = swap;
          }
      }
  }
  }
  
  // print out both arrays using pointer
  void print_values_ver2(char *string, int *pointer, int size)
  {
  int *i;
  
  printf("%s", string);
  printf("\n");
  
  for(i = pointer; i &lt; (pointer + size); i++)
  {
      printf("%d,", *i);
  }
  printf("\n\n");
  }
  </code></pre>
  
  <p>When I run the program and print data, the entered values are not sorted and remain at the same place. I would appreciate any help given.</p>