c++ - Sorting in arrays -


Sorting an array for the past: a [5] = {1,4,5,3,2} output Should the output of 0,1,2,3,4, using the concept of bubble to be 1,2,3,4,5 in ascending order, what would be my problem in my code

  int A [5] = {1,5,3, 2,4}; For (int i = 0; i  a [j + 1 ]) {Int t = a]; A [j] = a [j + 1]; A [j + 1] = t; }}} For (i = 0; i <5; i ++) cout & lt; & Lt; A [i];  

You can get your internal loop & lt; 4:

previous> int A [5] = {1,5,3,2,4}; For (int i = 0; i <5; i ++) {for (int j = 0; j & lt; 4; j ++) {if (a [j]> a [j + 1] } {Int t = a [j]]; A [j] = a [j + 1]; A [j + 1] = t; }}} For (i = 0; i <5; i ++) cout & lt; & Lt; A [i];

Comments