Skip to content

Commit cea59ce

Browse files
committed
Initial commit
0 parents  commit cea59ce

File tree

4 files changed

+666
-0
lines changed

4 files changed

+666
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test
2+
*~
3+
*.swp
4+

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
test: timsort.hpp test.cpp
3+
$(CXX) -Wall -Wextra -std=c++0x test.cpp -o $@

test.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
#include "timsort.hpp"
5+
6+
7+
template<typename T>
8+
int compare(T x, T y) {
9+
if(x == y) {
10+
return 0;
11+
}
12+
else if(x < 0) {
13+
return -1;
14+
}
15+
else {
16+
return 1;
17+
}
18+
}
19+
20+
int main() {
21+
std::vector<int> a;
22+
a.push_back(6);
23+
a.push_back(5);
24+
a.push_back(10);
25+
a.push_back(4);
26+
a.push_back(8);
27+
a.push_back(2);
28+
a.push_back(3);
29+
a.push_back(7);
30+
a.push_back(1);
31+
a.push_back(9);
32+
33+
timsort(a.begin(), a.end(), &compare<int>);
34+
35+
for(std::vector<int>::const_iterator i = a.begin();
36+
i != a.end();
37+
++i ) {
38+
std::cout << *i << std::endl;
39+
}
40+
return 0;
41+
}
42+

0 commit comments

Comments
 (0)