Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2c1050a
Лабораторная работа 3822Б1ПМ1 Зазнобин П.В.
Petr-Zaznobin Dec 23, 2022
63f78b9
Update SortsUnn.cpp
Petr-Zaznobin Dec 23, 2022
3169ead
Update SortsUnn.cpp
Petr-Zaznobin Dec 23, 2022
f7ea14f
Report
Petr-Zaznobin Dec 29, 2022
208a7c6
Rename SortsUnn.cpp to Sorts/SortsUnn.cpp
Petr-Zaznobin Jan 2, 2023
0f34237
Report
Petr-Zaznobin Jan 2, 2023
941c731
Add files via upload
Petr-Zaznobin Apr 6, 2023
59de1af
Update main.c
Petr-Zaznobin Apr 7, 2023
52bf520
Update main.c
Petr-Zaznobin Apr 7, 2023
4508707
Update main.c
Petr-Zaznobin Apr 7, 2023
eec169e
Update main.c
Petr-Zaznobin Apr 18, 2023
b0f37e2
Add files via upload
Petr-Zaznobin Apr 18, 2023
ceb9ca8
Gauss
Petr-Zaznobin May 18, 2023
43d688e
Gauss
Petr-Zaznobin May 18, 2023
8823476
Rename main.cpp to GAUSS.cpp
Petr-Zaznobin May 18, 2023
2a83335
Delete Gauss/cmake-build-debug directory
Petr-Zaznobin May 18, 2023
17e147e
Delete Gauss/main.dSYM/Contents directory
Petr-Zaznobin May 18, 2023
2ef41a0
Delete CMakeLists.txt
Petr-Zaznobin May 18, 2023
50ec848
Delete funcs.cpp
Petr-Zaznobin May 18, 2023
636dc97
Delete funcs.h
Petr-Zaznobin May 18, 2023
5fa0461
Delete matrix.cpp
Petr-Zaznobin May 18, 2023
4a5e713
Delete matrix.h
Petr-Zaznobin May 18, 2023
10fa97b
Delete vector.cpp
Petr-Zaznobin May 18, 2023
af35998
Delete vector.h
Petr-Zaznobin May 18, 2023
84cbca5
Add files via upload
Petr-Zaznobin May 18, 2023
b09c462
Update GAUSS.cpp
Petr-Zaznobin May 18, 2023
8ebe1b2
GAUSS.cpp
Petr-Zaznobin May 18, 2023
e771f41
Update funcs.cpp
Petr-Zaznobin May 19, 2023
ad79a8c
Add files via upload
Petr-Zaznobin May 19, 2023
5d0e41e
Delete funcs.cpp
Petr-Zaznobin May 25, 2023
9916cec
Delete matrix.cpp
Petr-Zaznobin May 25, 2023
4b4c117
Delete vector.cpp
Petr-Zaznobin May 25, 2023
01a8feb
Update funcs.h
Petr-Zaznobin May 25, 2023
50bd1a2
Update matrix.h
Petr-Zaznobin May 25, 2023
7042728
Update vector.h
Petr-Zaznobin May 25, 2023
e1c90db
Update gauss.cpp
Petr-Zaznobin May 25, 2023
c5e38ac
Update funcs.h
Petr-Zaznobin May 25, 2023
cccd56a
Update funcs.h
Petr-Zaznobin May 25, 2023
d12286a
Delete GAUSS.cpp
Petr-Zaznobin May 26, 2023
26c6f6d
Delete Gauss directory
Petr-Zaznobin May 26, 2023
b1a0dbc
Add files via upload
Petr-Zaznobin May 26, 2023
b1b3079
Update funcs.h
Petr-Zaznobin May 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Report.docx
Binary file not shown.
Binary file added Sorts/Report.docx
Binary file not shown.
284 changes: 284 additions & 0 deletions Sorts/SortsUnn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
#include "stdio.h"
#include "cstdlib"
#include "locale.h"
#include "time.h"
#include "string.h"

int menu() {
int v;
printf_s("1. Задать массив\n2. Отсортировать массив\n3. Выход\n");
scanf_s("%d", &v);
return v;
}

void swap(float* a, float* b) {
float tmp = *a;
*a = *b;
*b = tmp;
}

void bubble_sort(float* arr, int n) {
int i, j;
int flag = 0;
for (i = 0; i < n; i++) {
flag = 0;
for (j = 0; j < n - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
swap(&arr[j], &arr[j + 1]);
flag = 1;
}
}
if (flag == 0)
break;
}
}


void merge(float* in, float* out, int l, int m, int r) {
int l1, l2;
int index = 0;
l1 = l;
l2 = m + 1;
while (l1 <= m && l2 <= r) {
if (in[l1] <= in[l2]) {
out[index++] = in[l1++];
}
else {
out[index++] = in[l2++];
}
}
while (l1 > m && l2 <= r) {
out[index++] = in[l2++];
}
while (l2 > r && l1 <= m) {
out[index++] = in[l1++];
}
for (int i = 0; i < index; i++) {
in[l + i] = out[i];
}
}

void merge_sort(float* arr, float* tmp, int l, int r) {
int m = l + ((r - l) / 2);
if (l == r) {
return;
}
merge_sort(arr, tmp, l, m);
merge_sort(arr, tmp, m + 1, r);
merge(arr, tmp, l, m, r);
}



void countByte(unsigned int* arr, int size, int count[256], int Byte) { //исхоодный массив, размер массива, символьный массив, текущий разряд
int tmp1, tmp2; //временная переменная
int i;
unsigned char* arrc = 0; // символьный массив
arrc = (unsigned char*)malloc(sizeof(unsigned char) * size); //?????????????/
int bias; //cмещение (нужен для отрицательных чисел, потому что (-5 = -5 + bias) в беззнаковой системе
bias = sizeof(unsigned int); //он хранит размер беззнакового инта
arrc = (unsigned char*)arr; //делаю массив символов из предыдущего массива
for (i = 0; i < 256; i++) { //заполняю вспомогательный массив нулями
count[i] = 0;
}
for (i = 0; i < size; i++) { //накидываю сколько раз определенное число входило в массив
count[arrc[i * bias + Byte]]++; //??????????
}
tmp1 = count[0]; //распределяю по индескам куда ставить числа
count[0] = 0;
for (i = 1; i < 256; i++) {
tmp2 = count[i];
count[i] = count[i - 1] + tmp1; //теперь в count лежат индексы, на которые нужно ставить числа каждого индекса массива
tmp1 = tmp2;
}

}

void radix_sort(unsigned int* arr, int size, unsigned* arr_tmp) {
unsigned char* arrc = (unsigned char*)arr; //копирую массив чаров
int count[256];
int sizetype = sizeof(unsigned int);
int i, j;
for (i = 0; i < sizetype; i++) {
countByte(arr, size, count, i); //где i - это номер разряда
for (j = 0; j < size; j++) { //Заполняем числами с выведенной индексацией
arr_tmp[count[arrc[j * sizetype + i]]++] = arr[j];
}
for (j = 0; j < size; j++) { //Из временного массива в основной
arr[j] = arr_tmp[j];
}
}
}

void radixFloat(float* arr, float* arr_tmp, int N) {
int count = 0;
int i = 0;
radix_sort((unsigned int*)arr, (unsigned int)N, (unsigned int*)arr_tmp);
while (i < N) { //Считаем количество положительных чисел
if (arr[i] >= 0) {
count++;
}
i++;
}
for (i = 0; i < count; i++) {
arr_tmp[N - count + i] = arr[i];
}
count = N - count;
for (count = count--; count >= 0; count--) {
arr_tmp[count] = arr[i++];
}

for (i = 0; i < N; i++) {
arr[i] = arr_tmp[i];
}
}

int compare(const void* a, const void* b)
{
const float* ad, * bd;
ad = (const float*)a;
bd = (const float*)b;

if ((*ad - *bd) < 0) return -1;
else
{
if ((*ad - *bd) > 0) return 1;
else return 0;
}
}

int check(float* arr, float* arrforsort, int n) {
int f = 0;
int i = 0;
float* qarr = 0;
qarr = (float*)malloc(sizeof(float) * n);
qarr = arr;
qsort(qarr, n, sizeof(float), compare);
for (i = 0; i < n; i++) {
if (qarr[i] != arrforsort[i]) {
return 0;
}
}
return 1;
}


int main()
{
int v, n, v2, v3, i;
float* arrforsorts = 0;
float* arr = 0;
clock_t start, end;
setlocale(LC_ALL, "Rus");
while (true) {
int f = 0;
printf("Введите цифру, которая ссответсвует вашему выбору:\n");
v = menu();
switch (v) {
case(1):
{

printf("Укажите размерность массива:\n");
scanf_s("%d", &n);
arr = (float*) malloc(sizeof(float) * n);
arrforsorts = (float*)malloc(sizeof(float) * n);

printf("1. Заполнить с клавиатуры\n2. Заполнить автоматически (-1000 <= рандом < 1000)\n");
scanf_s("%d", &v2);
switch (v2) {
case(1):
{
printf("Введите %d чисел:\n", n);
for (i = 0; i < n; i++) {
printf("%d. ", i + 1);
scanf_s("%f", &arr[i]);
arrforsorts[i] = arr[i];
}
continue;
}
case(2):
{
for (i = 0; i < n; i++) {
arr[i] = (((float) rand() / RAND_MAX) * 1000) - (((float)rand() / RAND_MAX) * 1000);
arrforsorts[i] = arr[i];
}
continue;
}

default:
{
free(arrforsorts);
free(arr);
continue;
}
}
}
case (2):
{
printf("Выберите номер сортировки:\n1. Сортировка пузырьком\n2. Сортировка слиянием\n3. Поразрядная сортировка\n");
scanf_s("%d", &v3);
switch(v3) {
case(1):
{
start = clock();
bubble_sort(arrforsorts , n);
end = clock();
if (check(arr, arrforsorts, n) == 1) {
printf_s("OK\n");
printf_s("%d\n", (end - start));
}
else printf_s("ERORR!\n");
continue;
}
case(2):
{
float* out = 0;
out = (float*)malloc(sizeof(float)*n);
start = clock();
merge_sort(arrforsorts, out, 0, n-1);
end = clock();
if (check(arr, arrforsorts, n) == 1) {
printf_s("OK\n");
printf_s("%d\n", (end - start));
}
else printf_s("ERORR!\n");
free(out);
continue;
}
case(3):
{
float* arr_tmp = (float*)malloc(sizeof(float) * n);
start = clock();
radixFloat(arrforsorts, arr_tmp, n);
end = clock();
if (check(arr, arrforsorts, n) == 1) {
printf_s("OK\n");
printf_s("%d\n", (end - start));
}
else printf_s("ERORR!\n");
free(arr_tmp);
continue;
}
}
}
case(3):
{
f = 1;
}
default:
{
free(arr);
break;
}
}
if (f == 1) {

break;
}
free(arrforsorts);
free(arr);
}


}

Binary file added gauss/Debug/main.exe
Binary file not shown.
Binary file added gauss/Debug/main.pdb
Binary file not shown.
31 changes: 31 additions & 0 deletions gauss/gauss.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32802.440
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gauss", "gauss\gauss.vcxproj", "{50DFADFA-4BA5-4867-AD98-389099A4F460}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{50DFADFA-4BA5-4867-AD98-389099A4F460}.Debug|x64.ActiveCfg = Debug|x64
{50DFADFA-4BA5-4867-AD98-389099A4F460}.Debug|x64.Build.0 = Debug|x64
{50DFADFA-4BA5-4867-AD98-389099A4F460}.Debug|x86.ActiveCfg = Debug|Win32
{50DFADFA-4BA5-4867-AD98-389099A4F460}.Debug|x86.Build.0 = Debug|Win32
{50DFADFA-4BA5-4867-AD98-389099A4F460}.Release|x64.ActiveCfg = Release|x64
{50DFADFA-4BA5-4867-AD98-389099A4F460}.Release|x64.Build.0 = Release|x64
{50DFADFA-4BA5-4867-AD98-389099A4F460}.Release|x86.ActiveCfg = Release|Win32
{50DFADFA-4BA5-4867-AD98-389099A4F460}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CCA00ACE-C479-4CA7-9DB0-7A20A7C2FED7}
EndGlobalSection
EndGlobal
Binary file added gauss/gauss/Debug/funcs.obj
Binary file not shown.
24 changes: 24 additions & 0 deletions gauss/gauss/Debug/gauss.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
 gauss.cpp
C:\Users\pitza\source\repos\gauss\gauss\funcs.h(66,1): warning C4305: инициализация: усечение из "double" в "T"
with
[
T=float
]
C:\Users\pitza\source\repos\gauss\gauss\gauss.cpp(20): message : выполняется компиляция ссылки на экземпляр шаблон функции "void solver<float>(int)"
C:\Users\pitza\source\repos\gauss\gauss\funcs.h(83,24): warning C4244: =: преобразование "int" в "T", возможна потеря данных
with
[
T=float
]
C:\Users\pitza\source\repos\gauss\gauss\funcs.h(54,1): warning C4305: инициализация: усечение из "double" в "T"
with
[
T=float
]
C:\Users\pitza\source\repos\gauss\gauss\funcs.h(148): message : выполняется компиляция ссылки на экземпляр шаблон функции "bool is_null<T>(int,int,matrix<T> &)"
with
[
T=float
]
C:\Users\pitza\source\repos\gauss\gauss\gauss.cpp(20): message : выполняется компиляция ссылки на экземпляр шаблон функции "void solver<float>(int)"
gauss.vcxproj -> C:\Users\pitza\source\repos\gauss\Debug\main.exe
Binary file added gauss/gauss/Debug/gauss.obj
Binary file not shown.
11 changes: 11 additions & 0 deletions gauss/gauss/Debug/main.exe.recipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\pitza\source\repos\gauss\Debug\main.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>
Binary file added gauss/gauss/Debug/main.ilk
Binary file not shown.
Binary file added gauss/gauss/Debug/main.tlog/CL.command.1.tlog
Binary file not shown.
Binary file added gauss/gauss/Debug/main.tlog/CL.read.1.tlog
Binary file not shown.
Binary file added gauss/gauss/Debug/main.tlog/CL.write.1.tlog
Binary file not shown.
Binary file added gauss/gauss/Debug/main.tlog/link.command.1.tlog
Binary file not shown.
Binary file added gauss/gauss/Debug/main.tlog/link.read.1.tlog
Binary file not shown.
Binary file added gauss/gauss/Debug/main.tlog/link.write.1.tlog
Binary file not shown.
2 changes: 2 additions & 0 deletions gauss/gauss/Debug/main.tlog/main.lastbuildstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0:
Debug|Win32|C:\Users\pitza\source\repos\gauss\|
Binary file added gauss/gauss/Debug/matrix.obj
Binary file not shown.
Binary file added gauss/gauss/Debug/vc142.idb
Binary file not shown.
Binary file added gauss/gauss/Debug/vc142.pdb
Binary file not shown.
Binary file added gauss/gauss/Debug/vector.obj
Binary file not shown.
Loading