-
Notifications
You must be signed in to change notification settings - Fork 0
/
deletLocalMaxMin.cpp
104 lines (92 loc) · 2.38 KB
/
deletLocalMaxMin.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// MODIF
#include <iostream>
#include <algorithm>
#include <cmath>
#include "Matrix.hpp"
void deletLocalMaxMin(int **matrix, int N, int N2, int opt)
{
int max = -pow(2,31);
int min = pow(2,31) - 1;
int minIndex = 0;
int maxIndex = 0;
bool b = true;
if(!opt)
{
for(int i = 0; i < N; i++)
{
int j = 0;
while(j < N2)
{
if(b)
{
if(matrix[i][j] > max)
{
max = matrix[i][j];
maxIndex = j;
}
if(matrix[i][j] < min)
{
min = matrix[i][j];
minIndex = j;
}
} else
{
if((matrix[i][j] == max) || (matrix[i][j] == min))
{
matrix[i][j] = 0;
}
}
j++;
if((j == N2) && b)
{
b = false;
j = minIndex > maxIndex ? maxIndex : minIndex;
}
}
max = -pow(2,31);
min = pow(2,31) - 1;
minIndex = 0;
maxIndex = 0;
b = true;
}
} else
{
for(int i = 0; i < N; i++)
{
int j = 0;
while(j < N2)
{
if(b)
{
if(matrix[j][i] > max)
{
max = matrix[j][i];
maxIndex = j;
}
if(matrix[j][i] < min)
{
min = matrix[j][i];
minIndex = j;
}
} else
{
if((matrix[j][i] == max) || (matrix[j][i] == min))
{
matrix[j][i] = 0;
}
}
j++;
if((j == N2) && b)
{
b = false;
j = minIndex > maxIndex ? maxIndex : minIndex;
}
}
max = -pow(2,31);
min = pow(2,31) - 1;
minIndex = 0;
maxIndex = 0;
b = true;
}
}
}