Created
August 5, 2019 14:34
-
-
Save dertst/29fe9e9315fcc39f2bc01a430aa0d710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include"pch.h" | |
#include <iostream> | |
#include <stdio.h> | |
#include <Windows.h> | |
#include <ctime> | |
int* InputArray(int n) | |
{ | |
FILE *f; | |
fopen_s(&f, "C:\\temp\\intut.txt", "wt"); | |
int *collection = (int*)malloc(n * sizeof(int)); | |
for (int i = 0; i < n; i++) | |
{ | |
scanf_s("%d", &collection[i]); | |
fprintf(f, "%d", collection[i]); | |
} | |
return collection; | |
fclose(f); | |
} | |
int CalculateArray(int* collection, int a,int n) | |
{ | |
int result=0; | |
for (int i = 0; i < n; i++) | |
{ | |
if (collection[i] > a) | |
{ | |
result++; | |
} | |
} | |
return result; | |
} | |
struct Node { | |
int value; | |
struct Node *next; | |
struct Node *prev; | |
}; | |
struct List { | |
struct Node* first; | |
struct Node* last; | |
}; | |
struct List* create() { | |
struct List* list = (struct List*)malloc(sizeof(struct List)); | |
list->first = NULL; | |
list->last = NULL; | |
return list; | |
} | |
void insert( struct List* list) | |
{ | |
if (list->first == NULL && list->last == NULL) | |
{ | |
struct Node* node = (struct Node*)malloc(sizeof(struct Node)); | |
scanf_s("%d", &node->value); | |
node->next = NULL; | |
node->prev = NULL; | |
list->first = node; | |
list->last = node; | |
} | |
else { | |
struct Node* node = (struct Node*)malloc(sizeof(struct Node)); | |
scanf_s("%d",&node->value); | |
node->prev = list->last; | |
node->next = NULL; | |
list->last = node; | |
} | |
} | |
int ScrollList(int limit, struct List* list) | |
{ | |
printf("коллекция\n"); | |
if (list == NULL || list->first == NULL) | |
{ | |
return 0; | |
} | |
Node* curentNode = list->first; | |
int result = 0; | |
do { | |
if (curentNode->value > limit) | |
{ | |
printf("%d ", curentNode->value); | |
result++; | |
} | |
curentNode = curentNode->next; | |
} while (curentNode != list->last && curentNode != NULL); | |
printf("\n"); | |
return result; | |
} | |
int main() | |
{ | |
setlocale(LC_ALL, "Russian"); | |
int StartTime = clock(); | |
printf("Выбирете тип коллекции\nМассив(1)\nДвусвязный список(2)\nДвоичное дерево(3)\nДля выбора нужного типа коллекции введите номер соответствующего типа\n"); | |
int Type; | |
int n; | |
int Result; | |
scanf_s("%d", &Type); | |
printf("Введите размер коллекции"); | |
printf("\n"); | |
scanf_s("%d", &n); | |
if (Type == 1) | |
{ | |
int* collection=InputArray(n); | |
printf("Введите число с кототорым хотите сравнить элементы коллекции!"); | |
printf("\n"); | |
int a; | |
scanf_s("%d", &a); | |
Result=CalculateArray(collection, a, n); | |
} | |
else if(Type == 2) | |
{ | |
printf("Введите число с кототорым хотите сравнить элементы коллекции!"); | |
printf("\n"); | |
int a; | |
scanf_s("%d", &a); | |
struct List* list = create(); | |
for (int i = 0; i < n; i++) | |
{ | |
insert(list); | |
} | |
Result = ScrollList(a, list); | |
} | |
/* | |
else if(Type == 3) | |
{ | |
//Ввод двоичным деревом | |
} | |
*/ | |
int EndTime = clock(); | |
int Time = EndTime - StartTime ; | |
int Member = sizeof(int) * 8 + sizeof(int)*n; | |
printf("Количество чисел больше введённого: %d\nКоличество памяти требоемое для хранения данных: %d\nВремя выполнения операции: %d", Result,Member,Time); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment