Π’Π΅ΠΊΡΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ.
Π‘ΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° ΡΡΠ°ΡΠΈΡΠ΅ΡΠΊΠΈΡ
ΡΡΡΡΠΊΡΡΡ Π΄Π°Π½Π½ΡΡ
Cout. width (3) ;//ΡΠΈΡΠΈΠ½Π° ΠΏΠΎΠ»Ρ Π²ΡΠ²ΠΎΠ΄ΠΈΠΌΠΎΠ³ΠΎ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠ°. Cout. width (3) ;//ΡΠΈΡΠΈΠ½Π° ΠΏΠΎΠ»Ρ Π²ΡΠ²ΠΎΠ΄ΠΈΠΌΠΎΠ³ΠΎ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠ°. ΠΡΠ΄Π΅Π»Π΅Π½ΠΈΠ΅ Π΄ΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΎΠΉ ΠΏΠ°ΠΌΡΡΠΈ ΠΏΠΎΠ΄ ΠΌΠ°ΡΡΠΈΠ²Π°. Cout << «ΠΠ²Π΅Π΄ΠΈΡΠ΅ Π΅ΡΡ ΡΠ°Π· Π΄Π»Ρ ΡΡΠΎΠΉ ΡΡΠ΅ΠΉΠΊΠΈ» << endl; Π ΠΈΡ 1 — ΡΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° ΠΊΠ²Π°Π΄ΡΠ°ΡΠ½ΠΎΠΉ ΠΌΠ°ΡΡΠΈΡΡ. ΠΠ±Π»Π°ΡΡΠΈ ΠΏΠ°ΠΌΡΡΠΈ, Π²ΡΠ΄Π΅Π»ΡΠ΅ΠΌΠΎΠΉ ΠΏΠΎΠ΄ ΡΡΡΠΎΠΊΡ. ΠΠ° ΡΡΡΠΎΠΊΠΈ ΠΏΡΠΈΡΠ²Π°ΠΈΠ²Π°Π΅ΡΡΡ Π°Π΄ΡΠ΅Ρ Π½Π°ΡΠ°Π»Π°. ΠΡΠ²ΠΎΠ±ΠΎΠΆΠ΄Π΅Π½ΠΈΠ΅ Π΄ΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΎΠΉ ΠΏΠ°ΠΌΡΡΠΈ. Void zanulenieElementov (tMatr a, bMatr b, int str… Π§ΠΈΡΠ°ΡΡ Π΅ΡΡ >
Π’Π΅ΠΊΡΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ. Π‘ΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° ΡΡΠ°ΡΠΈΡΠ΅ΡΠΊΠΈΡ ΡΡΡΡΠΊΡΡΡ Π΄Π°Π½Π½ΡΡ (ΡΠ΅ΡΠ΅ΡΠ°Ρ, ΠΊΡΡΡΠΎΠ²Π°Ρ, Π΄ΠΈΠΏΠ»ΠΎΠΌ, ΠΊΠΎΠ½ΡΡΠΎΠ»ΡΠ½Π°Ρ)
Π’Π΅ΠΊΡΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ
//ΠΠ΅ΡΠΎΠ΄Ρ ΡΠΎΡΡΠΈΡΠΎΠ²ΠΊΠΈ.
//ΠΠ°ΡΡΠΈΠ²Ρ Π΄ΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΈΠ΅ Π΄Π²ΡΠΌΠ΅ΡΠ½ΡΠ΅.
//Π‘ΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² Π²ΡΠ΅Ρ ΡΡΡΠΎΠΊ Π΄Π²ΡΠΌΠ΅ΡΠ½ΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π° ΡΠ΅Π»ΡΡ ΡΠΈΡΠ΅Π».
//ΠΏΠΎ ΡΠ±ΡΠ²Π°Π½ΠΈΡ.
#include «iostream» .
#include «locale.h» .
#include.
using namespace std;
typedef bool boolVal; //ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΡΠΈΠΏΠ° ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² ΠΌΠ°ΡΡΠΈΠ²Π°.
typedef boolVal *bStr; //ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΡΠΈΠΏΠ° «ΡΠΊΠ°Π·Π°ΡΠ΅Π»Ρ Π½Π° telem» .
typedef bStr *bMatr;
//ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΡΠΈΠΏΠ° «ΡΠΊΠ°Π·Π°ΡΠ΅Π»Ρ Π½Π° ΡΠΊΠ°Π·Π°ΡΠ΅Π»Ρ Π½Π° telem» .
typedef int telem; //ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΡΠΈΠΏΠ° ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² ΠΌΠ°ΡΡΠΈΠ²Π°.
typedef telem *tStr; //ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΡΠΈΠΏΠ° «ΡΠΊΠ°Π·Π°ΡΠ΅Π»Ρ Π½Π° telem» .
typedef tStr *tMatr;
//ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΡΠΈΠΏΠ° «ΡΠΊΠ°Π·Π°ΡΠ΅Π»Ρ Π½Π° ΡΠΊΠ°Π·Π°ΡΠ΅Π»Ρ Π½Π° telem» .
int Color ();
void inputValMatr (bMatr a, int str, int sto);
void inputMatr (tMatr a, int str, int sto) ;
void handInput (tMatr a, int str, int sto) ;
void outputMatr (tMatr a, int str, int sto) ;
void sortVstavka (tMatr a, bMatr b, int str, int sto) ;
void zanulenieElementov (tMatr a, bMatr b, int str, int sto);
void outputBoolMatr (bMatr a, int str, int sto);
int main ().
{.
while (true).
{.
int i, j ;
int n = 0; //ΡΠΈΡΠ»ΠΎ ΡΡΡΠΎΠΊ ΠΌΠ°ΡΡΠΈΡΡ.
int m = 0; //ΡΠΈΡΠ»ΠΎ ΡΡΠΎΠ»Π±ΡΠΎΠ² ΠΌΠ°ΡΡΠΈΡΡ.
bool y;
tMatr a; //ΠΎΠ±ΡΡΠ²Π»ΡΠ΅ΡΡΡ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½Π°Ρ-ΡΠΊΠ°Π·Π°ΡΠ΅Π»Ρ Π½Π° ΡΠΊΠ°Π·Π°ΡΠ΅Π»Ρ Π½Π° telem.
bMatr b;
setlocale (LC_ALL," Russian") ;
cout < 3 (ΠΡΠΈΠΌΠ΅Ρ: 10 11): " ;
while (n < 3 && m < 3).
{.
cin.sync ();
try.
{.
char n1[3], m1[3];
cin >> n1 >> m1;
n = (int)atof (n1);
m = (int)atof (m1);
}.
catch (…).
{.
}.
cout << «ΠΠ΅Π²Π΅ΡΠ½ΡΠΉ Π²Π²ΠΎΠ΄, Π½ΡΠΆΠ½ΠΎ ΡΠΈΡΠ»ΠΎ ΡΡΡΠΎΠΊ< 20» << endl;
}.
a = new tStr [n] ;
//Π²ΡΠ΄Π΅Π»Π΅Π½ΠΈΠ΅ Π΄ΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΎΠΉ ΠΏΠ°ΠΌΡΡΠΈ ΠΏΠΎΠ΄ ΠΌΠ°ΡΡΠΈΠ²Π°.
//ΡΠΊΠ°Π·Π°ΡΠ΅Π»Π΅ΠΉ Π½Π° ΡΡΡΠΎΠΊΠΈ ΠΌΠ°ΡΡΠΈΠ²Π°.
for (i = 0; i < n; i++) //ΡΠΈΠΊΠ» Π²ΡΠ΄Π΅Π»Π΅Π½ΠΈΡ ΠΏΠ°ΠΌΡΡΠΈ ΠΏΠΎΠ΄ ΠΊΠ°ΠΆΠ΄ΡΡ ΡΡΡΠΎΠΊΡ.
*(a + i) = new telem [m] ;//ΠΊΠ°ΠΆΠ΄ΠΎΠΌΡ ΡΠ»Π΅ΠΌΠ΅Π½ΡΡ ΠΌΠ°ΡΡΠΈΠ²Π° ΡΠΊΠ°Π·Π°ΡΠ΅Π»Π΅ΠΉ.
//Π½Π° ΡΡΡΠΎΠΊΠΈ ΠΏΡΠΈΡΠ²Π°ΠΈΠ²Π°Π΅ΡΡΡ Π°Π΄ΡΠ΅Ρ Π½Π°ΡΠ°Π»Π°.
//ΠΎΠ±Π»Π°ΡΡΠΈ ΠΏΠ°ΠΌΡΡΠΈ, Π²ΡΠ΄Π΅Π»ΡΠ΅ΠΌΠΎΠΉ ΠΏΠΎΠ΄ ΡΡΡΠΎΠΊΡ.
b = new bStr [n] ;
for (i = 0; i < n; i++).
*(b + i) = new boolVal [m] ;
cout << «ΠΠ²Π΅Π΄ΠΈΡΠ΅ 0 — ΠΌΠ°ΡΡΠΈΡΠ° Π·Π°ΠΏΠΎΠ»Π½ΠΈΡΡΡ ΡΠ°ΠΌΠ°, Π²Π²Π΅Π΄ΠΈΡΠ΅ 1 ΠΈ Π²Π²ΠΎΠ΄ΠΈΡΠ΅ ΡΠΈΡΠ»Π° ΡΠ΅ΡΠ΅Π· enter. «;
cin >> y;
if (!y).
{.
inputMatr (a, n, m) ;
}.
else.
{.
handInput (a, n, m);
}.
inputValMatr (b, n, m);
if (n <= 20).
{.
cout << «ΠΡΡ ΠΎΠ΄Π½Π°Ρ ΠΌΠ°ΡΡΠΈΡΠ°: » ;
outputMatr (a, n, m) ;
sortVstavka (a, b, n, m);
cout << «ΠΠ°ΡΡΠΈΡΠ° Ρ ΠΎΡΡΠΎΡΡΠΈΡΠΎΠ²Π°Π½Π½ΡΠΌΠΈ ΡΡΡΠΎΠΊΠ°ΠΌΠΈ: «<< endl ;
zanulenieElementov (a, b, n, m);
outputMatr (a, n, m) ;
}.
else.
{.
cout << «ΠΠ°ΡΠ° ΠΌΠ°ΡΡΠΈΡΠ° ΠΠ ΠΠΠΠΠΠ’ Π² ΠΠ°ΡΡ ΠΊΠΎΠ½ΡΠΎΠ»Ρ ΠΏΠΎ ΡΠΈΡΠΈΠ½Π΅» << endl;
return;
}.
cout << endl ;
//ΠΡΠ²ΠΎΠ±ΠΎΠΆΠ΄Π΅Π½ΠΈΠ΅ Π΄ΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΎΠΉ ΠΏΠ°ΠΌΡΡΠΈ.
for (i = 0; i < n; i++).
delete a[i] ;
delete a ;
char isExit =0;
cout << «ΠΠ²Π΅Π΄ΠΈΡΠ΅ 1 Π΄Π»Ρ Π²ΡΡ ΠΎΠ΄Π° «;
try.
{.
cin >> isExit;
if (isExit==1).
break;
}.
catch (…).
{.
}.
}.
}.
void inputMatr (tMatr a, int str, int sto).
{.
for (int i = 0; i < str; i++).
for (int j = 0; j < sto; j++).
*(*(a + i) + j) = (str*sto) — (i + j);
}.
void inputValMatr (bMatr a, int str, int sto).
{.
for (int i = 0; i < str; i++).
for (int j = 0; j < sto; j++).
*(*(a + i) + j) = false;
}.
void handInput (tMatr a, int str, int sto).
{.
int input = 0;
int *inputPointer = &input;
int *elemPointer;
for (int i = 0; i < str; i++).
{.
for (int j = 0; j < sto; j++).
{.
elemPointer = (*(a + i) + j);
*elemPointer = 0;
while (*elemPointer == 0).
{.
try.
{.
cin >> *inputPointer;
*elemPointer = (int)input;
}.
catch (…).
{.
cout << «ΠΠ²Π΅Π΄ΠΈΡΠ΅ Π΅ΡΡ ΡΠ°Π· Π΄Π»Ρ ΡΡΠΎΠΉ ΡΡΠ΅ΠΉΠΊΠΈ» << endl;
}.
}.
}.
}.
}.
//ΡΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² ΠΌΠ°ΡΡΠΈΠ²Π° ΠΏΠΎ Π²ΠΎΠ·ΡΠ°ΡΡΠ°Π½ΠΈΡ ΠΌΠ΅ΡΠΎΠ΄ΠΎΠΌ Π²ΡΡΠ°Π²ΠΊΠΈ.
void sortVstavka (tMatr a, bMatr b, int str, int sto).
{.
telem *curElem = 0;
telem *nextElem = 0;
if ((str > 3) && (sto >3) && (str <= 20)).
{.
#pragma region |sto > str|.
//Π‘ΠΎΠΎΡΠ²Π΅ΡΡΡΠ²Π΅Π½Π½ΠΎ, Π΅ΡΠ»ΠΈ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΡΡΠΎΠ»Π±ΡΠΎΠ² Π±ΠΎΠ»ΡΡΠ΅ ΡΡΡΠΎΠΊ :
if (sto > str).
{.
telem curTemp;
int begSto = 0;
int begStr = 0;
int curStr=0;
double predelStr = 0;
double predelSto = 0;
//ΠΡΠΎΡ ΡΠΈΠΊΠ» ΡΠΎΠ΄Π΅ΡΠΆΠΈΡ 4 ΡΠΈΠΊΠ»Π° Π²ΡΡΠ°Π²Π½ΠΈΠ²Π°Π½ΠΈΡ ΠΈ ΠΏΠΎΠ²ΡΠΎΡΡΠ΅ΡΡΡ ΡΡΠΎΠ»Ρ;
//ΠΊΠΎ ΡΠ°Π·, ΡΡΠΎΠ±Ρ Π²ΡΠ΅ ΡΠ»Π΅ΠΌΠ΅Π½ΡΡ Π±ΡΠ»ΠΈ Π²ΡΡΠΎΠ²Π½Π΅Π½Ρ ΠΏΠΎ Π²ΠΎΠ·ΡΠ°ΡΡΠ°Π½ΠΈΡ.
for (int l=0;l<=((str/2)-sto+str+1);l++).
{.
begSto = 1;
- (sto/2 == 0)? predelSto = sto/2: predelSto = (sto/2)-1;
- (str/2==0)? begStr = (str/2)+1: begStr = (str/2);
predelStr = begStr+1;
//1-ΠΉ ΡΠΈΠΊΠ» Π²ΡΡΠ°Π²Π½ΠΈΠ²Π°Π½ΠΈΡ.
for (int curSto = begSto;
curSto <= predelSto; curSto++).
{.
curStr = begStr;
if (predelStr >0).
predelStr—;
while (curStr >= predelStr).
{.
boolVal *curBool = (*(b + curStr) + curSto);
boolVal *nextBool = (*(b + curStr — 1) + curSto);
curElem = (*(a + curStr) + curSto);
curTemp = *curElem;
if (curStr>0).
nextElem =.
(*(a + curStr — 1) +curSto);
if ((*curElem > *nextElem) && curStr > 0).
{.
- *curElem = *nextElem;
- *nextElem = curTemp;
}.
*curBool = true;
if (((curStr-1) >= 0) &&.
((curStr+1)<=str-1)).
{.
*nextBool = true;
}.
curStr—;
if ((curSto > (sto/2 + 1))).
break;
}.
}.
begSto = (sto-2);
predelStr = begStr+1;
//2-ΠΉ ΡΠΈΠΊΠ» Π²ΡΡΠ°Π²Π½ΠΈΠ²Π°Π½ΠΈΡ.
for (int curSto = begSto; curSto > predelSto; curSto—).
{.
curStr = begStr;
if (predelStr >0).
predelStr—;
while (curStr >= predelStr).
{.
boolVal *curBool =.
(*(b + curStr) + curSto);
boolVal *nextBool =.
(*(b + curStr — 1) + curSto);
curElem = (*(a + curStr) + curSto);
curTemp = *curElem;
if (curStr>0).
nextElem =.
(*(a + curStr — 1) + curSto);
if ((*curElem > *nextElem) && curStr > 0).
{.
- *curElem = *nextElem;
- *nextElem = curTemp;
}.
*curBool = true;
if (((curStr-1) >= 0) &&.
((curStr+1)<=str-1)).
{.
*nextBool = true;
}.
curStr—;
if ((curSto < (sto/2 — 1))).
break;
}.
}.
(str/2==0)? begStr = (str/2): begStr = (str/2)+0.5;
predelStr = begStr;
//3-ΠΉ ΡΠΈΠΊΠ» Π²ΡΡΠ°Π²Π½ΠΈΠ²Π°Π½ΠΈΡ.
for (int curSto = 1; curSto <= predelSto; curSto++).
{.
curStr = begStr+1;
if (predelStr < str-1).
predelStr++;
while (curStr <= predelStr).
{.
boolVal *curBool =.
(*(b + curStr) + curSto);
boolVal *nextBool =.
(*(b + curStr + 1).
+ curSto);
curElem =.
(*(a + curStr) + curSto);
curTemp =.
*curElem;
if (curStr<(str-1)).
nextElem =.
(*(a + curStr + 1) + curSto);
if ((*curElem > *nextElem).
&& curStr < str-1).
{.
- *curElem = *nextElem;
- *nextElem = curTemp;
}.
*curBool = true;
curStr++;
if ((curSto > (sto/2 + 1))).
break;
}.
}.
predelStr = begStr;
//4-ΠΉ ΡΠΈΠΊΠ» Π²ΡΡΠ°Π²Π½ΠΈΠ²Π°Π½ΠΈΡ.
for (int curSto = sto-2;
curSto > predelSto; curSto—).
{.
curStr = begStr+1;
if (predelStr < str-1).
predelStr++;
while (curStr <= predelStr).
{.
boolVal *curBool =.
(*(b + curStr) + curSto);
boolVal *nextBool =.
(*(b + curStr + 1) + curSto);
curElem = (*(a + curStr) + curSto);
curTemp = *curElem;
if (curStr<(str-1)).
nextElem =.
(*(a + curStr + 1) +.
curSto);
if ((*curElem > *nextElem)&&.
curStr < (str-1)).
{.
- *curElem = *nextElem;
- *nextElem = curTemp;
}.
*curBool = true;
curStr++;
if ((curSto < ((sto/2 — 1)))).
break;
}.
}.
}.
}.
#pragma endregion.
#pragma region |sto < str|.
if (sto < str).
{.
telem curTemp;
int begSto = 0;
int begStr;
if (str % 2 == 0).
begStr = (str / 2) — 1;
else.
begStr = (str / 2);
for (int l=0;l<=((str/2)-sto+str+1);l++).
{.
int curStr=begStr;
double predelSto;
double predelStr = 0;
predelSto = sto/2−1;
predelStr = begStr+1;
begSto = 0;
//1.
for (int curSto = begSto;
curSto <= predelSto; curSto++).
{.
curStr = begStr;
if (predelStr >1).
predelStr—;;
while (curStr >= predelStr).
{.
boolVal *curBool =.
(*(b + curStr) + curSto);
curElem = (*(a + curStr) + curSto);
curTemp = *curElem;
if (curStr<(str-1)).
nextElem =.
(*(a + curStr — 1) + curSto);
if ((*curElem > *nextElem) &&.
curStr <(str-1)).
{.
- *curElem = *nextElem;
- *nextElem = curTemp;
}.
*curBool = true;
curStr—;
}.
}.
//2-ΠΉ ΡΠΈΠΊΠ» Π²ΡΡΠ°Π²Π½ΠΈΠ²Π°Π½ΠΈΡ.
predelStr = begStr+1;for (int curSto = sto-1;
curSto > predelSto; curSto—).
{.
curStr = begStr;
if (predelStr > 1).
predelStr—;
while (curStr >= predelStr).
{.
boolVal *curBool =.
(*(b + curStr) + curSto);
curElem = (*(a + curStr) + curSto);
curTemp = *curElem;
if (curStr<(str-1)).
nextElem =.
(*(a + curStr — 1) + curSto);
if ((*curElem > *nextElem) &&.
curStr <(str-1)).
{.
- *curElem = *nextElem;
- *nextElem = curTemp;
}.
*curBool = true;
curStr—;
}.
}.
//3-ΠΉ ΡΠΈΠΊΠ» Π²ΡΡΠ°Π²Π½ΠΈΠ²Π°Π½ΠΈΡ.
if (str % 2 == 0).
begStr = (str / 2);
else.
begStr = (str / 2);
begSto = 0;
predelStr = begStr-1;
for (int curSto = begSto;
curSto <= predelSto; curSto++).
{.
curStr = begStr;
if (predelStr < (str-1)).
predelStr++;;
while (curStr <= predelStr).
{.
boolVal *curBool =.
(*(b + curStr) + curSto);
curElem = (*(a + curStr) + curSto);
curTemp = *curElem;
if (curStr<(str-1)).
nextElem =.
(*(a + curStr + 1) + curSto);
if ((*curElem > *nextElem) &&.
curStr < (str-1)).
{.
- *curElem = *nextElem;
- *nextElem = curTemp;
}.
*curBool = true;
curStr++;
}.
}.
//4-ΠΉ ΡΠΈΠΊΠ» Π²ΡΡΠ°Π²Π½ΠΈΠ²Π°Π½ΠΈΡ.
predelStr = begStr-1;
for (int curSto = sto-1;
curSto > predelSto; curSto—).
{.
curStr = begStr;
if (predelStr < (str-1)).
predelStr++;
while (curStr <= predelStr).
{.
boolVal *curBool =.
(*(b + curStr) + curSto);
curElem = (*(a + curStr) + curSto);
curTemp = *curElem;
if (curStr<(str-1)).
nextElem =.
(*(a + curStr + 1) + curSto);
if ((*curElem > *nextElem) &&.
curStr < (str-1)).
{.
- *curElem = *nextElem;
- *nextElem = curTemp;
}.
*curBool = true;
curStr++;
}.
}.
}.
}.
#pragma endregion.
#pragma region |sto == str|.
if (sto == str).
{.
telem curTemp;
for (int l=0;l<=((str/2)-sto+str+1);l++).
{.
int begSto = 0;
int begStr = 0;
int curStr=begStr;
double predelSto = 0;
double predelStr = 0;
begSto = 0;
if (str % 2 == 0).
begStr = (str / 2) — 1;
else.
begStr = (str / 2);
(sto/2 == 0)? predelSto = sto/2 :
predelSto = (sto/2)+0.5;
predelStr = begStr+1;
for (int curSto = begSto;
curSto <= predelSto; curSto++).
{.
curStr = begStr;
if (predelStr >0).
predelStr—;
while (curStr >= predelStr).
{.
boolVal *curBool =.
(*(b + curStr) + curSto);
boolVal *nextBool =.
(*(b + curStr — 1) + curSto);
curElem = (*(a + curStr) + curSto);
curTemp = *curElem;
if (curStr>0).
nextElem =.
(*(a + curStr — 1) + curSto);
if ((*curElem > *nextElem) &&.
curStr > 0).
{.
- *curElem = *nextElem;
- *nextElem = curTemp;
}.
*curBool = true;
curStr—;
}.
}.
//2-ΠΉ ΡΠΈΠΊΠ» Π²ΡΡΠ°Π²Π½ΠΈΠ²Π°Π½ΠΈΡ.
predelStr = begStr+1;
for (int curSto = sto-1;
curSto > predelSto; curSto—).
{.
curStr = begStr;
if (predelStr > 0).
predelStr—;
while (curStr >= predelStr).
{.
boolVal *curBool =.
(*(b + curStr) + curSto);
boolVal *nextBool =.
(*(b + curStr — 1) + curSto);
curElem = (*(a + curStr) + curSto);
curTemp = *curElem;
if (curStr>0).
nextElem = (*(a + curStr — 1) +.
curSto);
if ((*curElem > *nextElem) &&.
curStr > 0).
{.
- *curElem = *nextElem;
- *nextElem = curTemp;
}.
*curBool = true;
curStr—;
}.
}.
if (str % 2 == 0).
{.
begStr = (str / 2);
begSto = sto-1;
}.
else.
{.
begStr = (str / 2)+1;
begSto = sto-2;
}.
predelStr = begStr-1;
//3-ΠΉ ΡΠΈΠΊΠ» Π²ΡΡΠ°Π²Π½ΠΈΠ²Π°Π½ΠΈΡ.
for (int curSto = begSto; curSto >= predelSto; curSto—).
{.
curStr = begStr;
if (predelStr < (str-1)).
predelStr++;
while (curStr <= predelStr).
{.
boolVal *curBool =.
(*(b + curStr) + curSto);
boolVal *nextBool =.
(*(b + curStr + 1) + curSto);
curElem = (*(a + curStr) + curSto);
curTemp = *curElem;
if (curStr<(str-1)).
nextElem = (*(a + curStr + 1) + curSto);
if ((*curElem > *nextElem) &&.
curStr < (str-1)).
{.
- *curElem = *nextElem;
- *nextElem = curTemp;
}.
*curBool = true;
curStr++;
}.
}.
if (str % 2 == 0).
{.
begStr = (str / 2);
begSto = 0;
}.
else.
{.
begStr = (str / 2)+1;
begSto = 1;
}.
predelStr = begStr-1;
//4-ΠΉ ΡΠΈΠΊΠ» Π²ΡΡΠ°Π²Π½ΠΈΠ²Π°Π½ΠΈΡ.
for (int curSto = begSto;
curSto < predelSto; curSto++).
{.
curStr = begStr;
if (predelStr < (str-1)).
predelStr++;
while (curStr <= predelStr).
{.
boolVal *curBool =.
(*(b + curStr) + curSto);
boolVal *nextBool =.
(*(b + curStr + 1) + curSto);
curElem = (*(a + curStr) + curSto);
curTemp = *curElem;
if (curStr<(str-1)).
nextElem =.
(*(a + curStr + 1) + curSto);
if ((*curElem > *nextElem) &&.
curStr < (str-1)).
{.
- *curElem = *nextElem;
- *nextElem = curTemp;
}.
*curBool = true;
curStr++;
}.
}.
}.
}.
#pragma endregion.
}.
if ((str == 3) && (sto == 3)).
{.
int var = 0;
int *one = (*(a + 1) + 1);
int *two = (*(a + 0) + 1);
if (one > two).
{.
var = *one;
- *one = *two;
- *two = var;
}.
}.
}.
void zanulenieElementov (tMatr a, bMatr b, int str, int sto).
{.
for (int stro = 0; stro <= (str -1); stro++).
{.
for (int stol = 0; stol <= (sto -1); stol++).
{.
if (*(*(b + stro) + stol) == false).
{.
*(*(a + stro) + stol) = 0;
}.
}.
}.
}.
void outputMatr (tMatr a, int str, int sto).
{ int i, j ;
for (i = 0; i < str; i++).
{for (j = 0; j < sto; j++).
{cout.width (3) ;//ΡΠΈΡΠΈΠ½Π° ΠΏΠΎΠ»Ρ Π²ΡΠ²ΠΎΠ΄ΠΈΠΌΠΎΠ³ΠΎ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠ°.
cout << *(*(a + i) + j) << ' ' ;
}.
cout << ««;
}.
}.
void outputBoolMatr (bMatr a, int str, int sto).
{ int i, j ;
for (i = 0; i < str; i++).
{for (j = 0; j < sto; j++).
{cout.width (3) ;//ΡΠΈΡΠΈΠ½Π° ΠΏΠΎΠ»Ρ Π²ΡΠ²ΠΎΠ΄ΠΈΠΌΠΎΠ³ΠΎ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠ°.
cout << *(*(a + i) + j) << ' ' ;
}.
cout << ««;
}.
}.
Π Π΅Π·ΡΠ»ΡΡΠ°ΡΡ ΡΠ΅ΡΡΠΈΡΠΎΠ²Π°Π½ΠΈΡ
Π ΠΈΡ 1 — ΡΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° ΠΊΠ²Π°Π΄ΡΠ°ΡΠ½ΠΎΠΉ ΠΌΠ°ΡΡΠΈΡΡ
Π ΠΈΡ 2 — ΡΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° ΠΏΡΡΠΌΠΎΡΠ³ΠΎΠ»ΡΠ½ΠΎΠΉ ΠΌΠ°ΡΡΠΈΡΡ #1
Π ΠΈΡ 3 — ΡΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° ΠΏΡΡΠΌΠΎΡΠ³ΠΎΠ»ΡΠ½ΠΎΠΉ ΠΌΠ°ΡΡΠΈΡΡ #1
ΡΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° Π΄Π°Π½Π½ΡΠ΅ ΠΌΠ°ΡΡΠΈΡΠ°.
Π ΠΈΡΡΠ½ΠΎΠΊ 4 — Π²ΡΠ²ΠΎΠ΄ ΡΠ²Π΅Π΄ΠΎΠΌΠ»Π΅Π½ΠΈΡ ΠΎ Π½Π΅ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΠΎΡΡΠΈ Π²Π²ΠΎΠ΄Π° Π΄Π°Π½Π½ΡΡ .