-
Notifications
You must be signed in to change notification settings - Fork 0
/
sorter.cpp
46 lines (40 loc) · 837 Bytes
/
sorter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Sorter
*/
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
//system("uname -a");
if(argc < 2) {
cerr << "Empty parameters!" << endl;
return -1;
}
//reading block
FILE* inputFile = fopen(argv[1], "rb");
if(!inputFile) {
cerr << "Empty file!" << endl;
return -2;
}
int n;
fread(&n, sizeof(int), 1, inputFile);
vector<int> array(n);
for(int i = 0; i < n; i++) {
fread(&array[i], sizeof(int), 1, inputFile);
}
fclose(inputFile);
delete(inputFile);
//sorting block
sort(&array[0], &array[n]);
//writing block into file
FILE* outputFile = fopen("outSort", "wb");
fwrite(&n, sizeof(int), 1, outputFile);
for(int i = 0; i < n; i++) {
fwrite(&array[i], sizeof(int), 1, outputFile);
}
fclose(outputFile);
return 0;
}