-
Notifications
You must be signed in to change notification settings - Fork 0
/
useful.h
74 lines (62 loc) · 2.08 KB
/
useful.h
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
65
66
67
68
69
70
71
72
73
74
#ifndef USEFUL_H_INCLUDED
#define USEFUL_H_INCLUDED
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <chrono>
#include <algorithm>
#include <thread>
#include <exception>
///**** COMPARE ****///
struct Compare {
template<typename T>
bool operator()(T* a, T* b) const { return *a < *b; }
template<typename T>
bool operator()(T a, T b) const { return a < b; }
};
///**** COMPARE ****///
template<typename T> inline bool compareValues(T* a, T* b) { return *a < *b; }
template<typename T> inline bool compareValues(T a, T b) { return a < b; }
/// Verify if an array given as parameter is sorted, send an exception if not
template<typename T> inline int verify(T tab) {
try{
for (unsigned int i = 1; i < tab.size(); i++) {
if (compareValues(tab[i], tab[i-1])) {
throw std::exception();
}
}
}
catch(std::exception ex) {
std::cerr << "ERROR : The array isn't well sorted" << std::endl;
return 1;
}
return 0;
}
///**** Input ****///
void openFile(std::string nom, std::vector<unsigned int>& tab);
void openFile(std::string nom, std::vector<std::string*>& tab);
///**** getByte ****///
short int getByte(unsigned int elem, unsigned int i);
short int getByte(std::string* elem, unsigned int i);
///**** getMaxLength ****///
std::size_t getMaxLength(std::vector<unsigned int>& tab);
std::size_t getMaxLength(std::vector<std::string*>& tab);
///**** Printing ****///
void inline print(std::vector<unsigned int> arr) {
for(const auto& elem : arr) {
std::cout << elem << std::endl;
}
}
void inline print(std::vector<std::string*> arr) {
for(const auto& elem : arr) {
std::cout << *elem << std::endl;
}
}
///**** Sorting ****///
/** LSD **/
template<typename T> void LSDRadixSort(std::vector<T>& tab);
/** MSD **/
template<typename T> void MSDRadixSort(std::vector<T>& tab);
template<typename T> void MSDRadixSort(std::vector<T>& tab, std::vector<T>& tabAux, int low, int high, int digit);
#endif // USEFUL_H_INCLUDED