-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.cpp
40 lines (37 loc) · 1.01 KB
/
sort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// MODIF
#include <iostream>
#include "Matrix.hpp"
void sort(int **matrix, int N1, int N2, int index, int opt)
{
if(opt)
{
std::cout<<"\nSort by string index = "<<index<<"\n";
for(int i = 1; i < N2; i++)
{
for(int j = 0; j < N2 - i; j++)
{
if(matrix[index][j] > matrix[index][j+1])
{
int tmp = matrix[index][j];
matrix[index][j] = matrix[index][j+1];
matrix[index][j+1] = tmp;
}
}
}
} else
{
std::cout<<"\nSort by column index = "<<index<<"\n";
for(int i = 1; i < N1; i++)
{
for(int j = 0; j < N1 - i; j++)
{
if(matrix[j][index] > matrix[j+1][index])
{
int tmp = matrix[j][index];
matrix[j][index] = matrix[j+1][index];
matrix[j+1][index] = tmp;
}
}
}
}
}