c - insertion sort code using insert and insertsort! -


I have written a code for entry sort but it is NT sorting. Please help me make desired changes to mycode . Thanx

 contains  # Stdio.h & gt; Int comparison (int a, int b) {if (a & gt; b) return 1; And if (A, L; B) returns -1; Else if (a == b) 0; } Enter zero (int m, int ms [], int size) {int j, k; Find out the correct position {if (compare (m, ms [j]) break; // trust: the right position for j (k = 0; j = l; j = l; s; j ++) Size -1; k & gt; = j; k--) // Correct shift values> MMS [K + 1] = MS [K]; MS [J] = M;} // Insert} Zero insert suit (The integer ms [], integer size) is calculated from the mosaic of ms [ja -1] from {int j; // loop initiality: // ms [0] (j = 1; j & lt; size; j ++) {insert (MS [J], MS, J);}} Zero main () {int i, arr [5] = {55,66,22,44,39}; printf ("sorting \ n"); insertSort (arrival, 5); for (i = 0; i & Lt; 5; i ++) {printf ("\ n% d", ARR [i]);}}  

This is my xact code .. I enter two functions and sort Insert!

You are testing the value of of , perhaps You want something like this:

  If (compare (m, ms [j]) & lt; = 0) break;  

In addition, Remove the curly bracements inside the function Insert , they can structure your code. Want screwing. The statement given after break should not be inside the first loop body.

By the way, if you make your code simple and hard, then forgetting that you will be less likely to fool you. Proper indentation will help you easily visualize the structure of your code. For example: Enter

  zero (int a [], int n, int e) {int j; For (J = N - 1; J> = 0 & amp; A [J]> E; J - A) [J + 1] = A [J]; A [J + 1] = E; } Zero entry_sort (int a [], int n) {int i; Enter (i = 1; i & lt; n; i ++) for (A, I, A [I]); }  

Comments