Difficulty printing each iteration of a transposition sorting algorithm

To print sequence, you have to add statements to print sequence.

void transposition (int a[], int n)
{
   int i, j;

   for (i = 0; i < n; i++) {
      for (j = i + 1; j < n; j++) {
         if (a[i] > a[j]) {
            swap(&a[i], &a[j]);
         }
      }
      printf("\nAfter pass %d: ", i);

      /* add this */
      for (j = 0; j < n; j++) {
         printf("%d ", a[j]);
      }

   }
}

Points to change from the code in main()

   for (i = 0; i < SIZE; i++) {
      printf("%d ", arr[i]);
   }

are:

  • Change i to j because i is used in the outer loop.
  • Change arr to a according to the argument.
  • Change SIZE to n according to the argument.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top