Arranging numbers c# code -


can fix code? it's supposed arrange numbers in order lowest highest. im having trouble running code...it wont print either. thanks

class program {     static void main(string[] args)     {         int[] in_ar_numbers = { 3, 2, 1, 6, 5, 4, 9, 8, 7 };          printarray(in_ar_numbers);         bubblesort(in_ar_numbers);         console.readline();     }      static void bubblesort(int[] in_ar_numberssorted)     {         int in_temp = 0;         bool bl_hasswapped = false;         int in_swapcount = 0;                  {             bl_hasswapped = false;              (int j = 0; j < in_ar_numberssorted.length - 1; j++)             {                 if (in_ar_numberssorted[j] > in_ar_numberssorted[j + 1])                 {                     in_temp = in_ar_numberssorted[j + 1];                     in_ar_numberssorted[j + 1] = in_ar_numberssorted[j];                     in_ar_numberssorted[j] = in_temp;                     bl_hasswapped = true;                     in_swapcount++;                 }             }         }         while (bl_hasswapped);          printarray(in_ar_numberssorted);     } } 

your not writing out in code given.

using system;  public class program {     public static void main(string[] args)     {         int[] in_ar_numbers = { 3, 2, 1, 6, 5, 4, 9, 8, 7 };          bubblesort(in_ar_numbers);          foreach (var in in_ar_numbers)         {             console.writeline(i);         }          console.readline();     }      static void bubblesort(int[] in_ar_numberssorted)     {         int in_temp = 0;         bool bl_hasswapped = false;         int in_swapcount = 0;                  {             bl_hasswapped = false;              (int j = 0; j < in_ar_numberssorted.length - 1; j++)             {                 if (in_ar_numberssorted[j] > in_ar_numberssorted[j + 1])                 {                     in_temp = in_ar_numberssorted[j + 1];                     in_ar_numberssorted[j + 1] = in_ar_numberssorted[j];                     in_ar_numberssorted[j] = in_temp;                     bl_hasswapped = true;                     in_swapcount++;                 }             }         }         while (bl_hasswapped);     }    } 

gives

1 2 3 4 5 6 7 8 9

i removed printarray function isn't in code given , added loop write array out:

foreach (var in in_ar_numbers) {   console.writeline(i); } 

(fiddle)


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -