-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread-quick-sort.cpp
More file actions
64 lines (49 loc) · 1.46 KB
/
read-quick-sort.cpp
File metadata and controls
64 lines (49 loc) · 1.46 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <iostream>
#include <vector>
struct Client {
std::string account;
std::string name;
std::string weigth;
std::string age;
};
int compare (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
}
int main() {
std::cout<<"\n\n";
std::cout<<"Quick sort in C++\n\n";
std::ifstream inFile("registration.txt");
const int size = 5;
int i = 0;
Client clients[size];
int accs[size];
if (inFile.is_open()) {
std::string line;
while(std::getline(inFile,line)) {
std::stringstream ss(line);
std::getline(ss,clients[i].account,',');
std::cout<<"\""<<clients[i].account<<"\"";
std::getline(ss,clients[i].name,',');
std::cout<<", \""<<clients[i].name<<"\"";
std::getline(ss,clients[i].weigth,',');
std::cout<<", \""<<clients[i].weigth<<"\"";
std::getline(ss,clients[i].age,',');
std::cout<<", \""<<clients[i].age<<"\"";
accs[i] = std::stoi(clients[i].account);
std::cout<<"\n";
i = i + 1;
}
}
std::cout<<"\n\n";
std::cout<<"No sorted:\n";
for (i=0; i<size; i++) printf ("%d ",accs[i]);
std::cout<<"\n\n";
std::cout<<"Quick sorted:\n";
qsort (accs, size, sizeof(int), compare);
for (i=0; i<size; i++) printf ("%d ",accs[i]);
std::cout<<"\n\n";
return 0;
}