Сделал 1 Задание со списками
This commit is contained in:
parent
5dbf4901b8
commit
632a718df1
71 changed files with 106 additions and 0 deletions
37
ProcessingSequences/Third/count_max_local.c
Normal file
37
ProcessingSequences/Third/count_max_local.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include "count_max_local.h"
|
||||
|
||||
int max(int first, int second) {
|
||||
if (first > second) {
|
||||
return first;
|
||||
}
|
||||
return second;
|
||||
}
|
||||
|
||||
|
||||
int getCountMaxLocal(FILE *file) {
|
||||
int current_n, last, length, maxLen;
|
||||
if (fscanf(file, "%d", ¤t_n) != 1) {
|
||||
printf("File is empty!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
last = current_n;
|
||||
maxLen = EMPTY;
|
||||
length = 1;
|
||||
|
||||
while (fscanf(file, "%d", ¤t_n) == 1) {
|
||||
if (last == current_n) {
|
||||
if (length) length++;
|
||||
} else {
|
||||
if (last > current_n) {
|
||||
maxLen = max(maxLen, length);
|
||||
length = EMPTY;
|
||||
} else {
|
||||
length = 1;
|
||||
}
|
||||
}
|
||||
|
||||
last = current_n;
|
||||
}
|
||||
return max(maxLen, length);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue