Skip to content

Commit 3418225

Browse files
committed
ahh
1 parent d34d96f commit 3418225

5 files changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
int main(int argc, char const *argv[]) {
5+
6+
std::string string = "hello";
7+
8+
std::cout << string.c_str() << std::endl;
9+
10+
return 0;
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
#include <list>
3+
4+
class Position;
5+
class Tree;
6+
7+
class Position {
8+
public:
9+
int& operator*();
10+
Position parent() const;
11+
std::list<Position> children() const;
12+
bool isRoot() const;
13+
bool isExternal() const;
14+
};
15+
16+
class Tree {
17+
public:
18+
class Position;
19+
20+
public:
21+
int size() const;
22+
bool empty() const;
23+
Position root() const;
24+
std::list<Position> positions() const;
25+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "Position.h"
2+
#include <iostream>
3+
4+
int main(int argc, char const *argv[]) {
5+
std::cout << "Hello World" << std::endl;
6+
7+
Tree tree;
8+
9+
return 0;
10+
}

source/chpt_9_misc/main.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <cstdlib>
2+
#include <ctime>
3+
#include <iostream>
4+
#include <vector>
5+
#include "merge.hpp"
6+
7+
void printVector(std::vector<int> const &vector) {
8+
for (int number : vector) {
9+
std::cout << number << " ";
10+
} std::cout << "\n";
11+
}
12+
13+
int main(int argc, char const *argv[]) {
14+
std::vector<int> vector_even({
15+
83, 13, 29, 57, 63, 35,
16+
92, 30, 57, 57, 43, 57,
17+
26, 36, 46, 12, 29, 78,
18+
39, 28, 75, 77, 52, 91,
19+
88, 13, 23, 12, 99, 93,
20+
14, 82, 96, 85, 92, 59,
21+
});
22+
23+
std::vector<int> vector_odd({
24+
83, 13, 29, 57, 63, 35,
25+
92, 30, 57, 57, 43, 57,
26+
26, 36, 46, 12, 29, 78,
27+
39, 28, 75, 77, 52, 91,
28+
88, 13, 23, 12, 99, 93,
29+
14, 82, 96, 85, 92, 59,
30+
});
31+
32+
33+
34+
std::vector<int> s1({2, 5, 8, 11, 12, 14, 15});
35+
std::vector<int> s2({3, 9, 10, 18, 19, 22, 25});
36+
37+
std::vector<int> merged = merge(s1, s2);
38+
39+
printVector(merged);
40+
41+
return 0;
42+
}

source/chpt_9_misc/merge.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
#include <vector>
3+
4+
std::vector<int> merge(std::vector<int> s_1, std::vector<int> s_2) {
5+
6+
int i = 0;
7+
int j = 0;
8+
std::vector<int> S;
9+
10+
while (i < s_1.size() && j < s_2.size()) {
11+
if (s_1[i] <= s_2[j]) {
12+
S.push_back(s_1[i]);
13+
i++;
14+
} else {
15+
S.push_back(s_2[j]);
16+
j++;
17+
}
18+
}
19+
20+
while (i < s_1.size()) {
21+
S.push_back(s_1[i]);
22+
i++;
23+
}
24+
while (j < s_2.size()) {
25+
S.push_back(s_2[j]);
26+
j++;
27+
}
28+
29+
return S;
30+
}

0 commit comments

Comments
 (0)