Вместо статичного массива теперь сипользует malloc, поэтому теперь возможно сортировать массивы размера больше 1000000
This commit is contained in:
parent
0d98154944
commit
22da302535
8 changed files with 25 additions and 12 deletions
BIN
Sorting/9Ex/a.out
Normal file
BIN
Sorting/9Ex/a.out
Normal file
Binary file not shown.
12
Sorting/9Ex/leak.out
Normal file
12
Sorting/9Ex/leak.out
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# LeakReport
|
||||||
|
# from new @ | size # Pointer Addr
|
||||||
|
L 0x402b51 64 # 0xf17920
|
||||||
|
L 0x4026ba 80000000 # 0x7ff8765bc010
|
||||||
|
L 0x4026ba 48 # 0xf179b0
|
||||||
|
L 0x402cc9 80000000 # 0x7ff87fe54010
|
||||||
|
L 0x4026a5 80000000 # 0x7ff87b208010
|
||||||
|
L 0x4026a5 48 # 0xf17970
|
||||||
|
# total allocation requests: 8 ; max. mem used 234375 kBytes
|
||||||
|
# leak 240000160 Bytes :-(
|
||||||
|
# .. that is 234375 kByte!! A lot ..
|
||||||
|
WORK TIME - 00:00:14.06
|
|
@ -3,7 +3,7 @@
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
int main() {
|
int main(void) {
|
||||||
FILE * file = getFile();
|
FILE * file = getFile();
|
||||||
double * array;
|
double * array;
|
||||||
int length;
|
int length;
|
||||||
|
@ -11,7 +11,7 @@ int main() {
|
||||||
if (file == NULL) return -1;
|
if (file == NULL) return -1;
|
||||||
array = getArray(file);
|
array = getArray(file);
|
||||||
if (array == NULL) return -2;
|
if (array == NULL) return -2;
|
||||||
length = (int)array[0];
|
length = (int)array[0] - 1;
|
||||||
|
|
||||||
array = &array[1];
|
array = &array[1];
|
||||||
printArray(array, length);
|
printArray(array, length);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
all: main.o seagwithsob.o tools.o
|
all: main.o seagwithsob.o tools.o
|
||||||
gcc main.o seagwithsob.o tools.o && del *.o
|
gcc main.o seagwithsob.o tools.o && rm *.o
|
||||||
a.exe
|
./a.out
|
||||||
|
|
||||||
main.o: main.c
|
main.o: main.c
|
||||||
gcc -c main.c
|
gcc -c main.c
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#include "seagwithsob.h"
|
#include "seagwithsob.h"
|
||||||
|
|
||||||
void sort(double * array, int length) {
|
void sort(double * array, int length) {
|
||||||
double zero[length];
|
double * zero = (double *)malloc(length * sizeof(double));
|
||||||
double unit[length];
|
double * unit = (double *)malloc(length * sizeof(double));
|
||||||
|
|
||||||
int index, timer = -clock();
|
int index, timer = -clock();
|
||||||
|
|
||||||
for (int j = 0; j < 63; ++j) {
|
for (int j = 0; j < 63; ++j) {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define SEAGWITHSOB
|
#define SEAGWITHSOB
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
FILE * getFile() {
|
FILE * getFile(void) {
|
||||||
char filename[50];
|
char filename[50];
|
||||||
|
|
||||||
printf("Enter file name: ");
|
printf("Enter file name: ");
|
||||||
if (scanf("%s", &filename) == 1) {
|
if (scanf("%s", filename) == 1) {
|
||||||
FILE * file = fopen(filename, "r");
|
FILE * file = fopen(filename, "r");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
printf("Error file!\n)");
|
printf("Error file!\n)");
|
||||||
|
@ -19,7 +19,6 @@ FILE * getFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
double * getArray(FILE * file) {
|
double * getArray(FILE * file) {
|
||||||
char filename[50];
|
|
||||||
int i, size = 2;
|
int i, size = 2;
|
||||||
double * array = NULL;
|
double * array = NULL;
|
||||||
double current;
|
double current;
|
||||||
|
@ -53,7 +52,7 @@ bool orderliness(double * array, int length) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void randomArray() {
|
void randomArray(void) {
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
printf("Enter length of array: ");
|
printf("Enter length of array: ");
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
|
|
||||||
#define exp -1.e-6
|
#define exp -1.e-6
|
||||||
|
|
||||||
FILE * getFile();
|
FILE * getFile(void);
|
||||||
double * getArray(FILE * file);
|
double * getArray(FILE * file);
|
||||||
bool orderliness(double * array, int length);
|
bool orderliness(double * array, int length);
|
||||||
void randomArray();
|
void randomArray(void);
|
||||||
void generate(double * array, int length);
|
void generate(double * array, int length);
|
||||||
void printArray(double * array, int length);
|
void printArray(double * array, int length);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue