Streamlining of



  • int col = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (matrix[i][j] != 0) { 
                col++; 
            }
            if (col == m) {
                for (i = 0; i < n; i++) {
                    for (int j1 = 0; j1 < m; ++j1) {
                        int pos = j1;
                        int tmp = matrix[i][pos];
                        for (j = j1 + 1; j < m; ++j) {
                            if (matrix[i][j] < tmp) {
                                pos = j;
                                tmp = matrix[i][j];
                            }
                        }
                        matrix[i][pos] = matrix[i][j1];
                        matrix[i][j1] = tmp; // меняем местами наименьший с a[j1]
                    }
                }
            } 
        }
    }
    

    This slice of the code shall be sorted by the height of the line elements in a matrix where there are no zero elements (if any one is left unchanged). But in fact, he's sorting all the lines, I can't figure out what I'm wrong about, say thank you in advance! Choice.



  • Move the energie col in the first cycle

    And why do you need a second cycle of i?


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2