-
Notifications
You must be signed in to change notification settings - Fork 0
/
see_ranking.cpp
47 lines (39 loc) · 927 Bytes
/
see_ranking.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
47
#include "main.h"
void shell_sort(std::vector<Question>& arr, int size)
{
for (int gap = size / 2; gap > 0; gap /= 2)
{
for (int i = gap; i < size; i += 1)
{
Question temp = arr[i];
int j;
for (j = i; j >= gap && arr[j - gap].get_wrong_answers() < temp.get_wrong_answers(); j -= gap)
arr[j] = arr[j - gap];
arr[j] = temp;
}
}
}
void see_ranking(std::string file)
{
FileHandler f(file);
std::vector<Question> list;
std::string obj;
while ((obj = f.read_from_file()) != "")
{
list.push_back(Question::deserialize(obj));
}
shell_sort(list, list.size());
for (int i = 0; i < list.size(); i++)
{
if (i == 0)
{
std::cout << "Primo Posto:\n\n1) " << list[i].get_question() << "\n\n------------------------------\n\n";
}
else
{
std::cout << i << ") " << list[i].get_question() << "\n";
}
}
std::cout << std::endl;
pause();
}