blob: 753cdf5d2f25328e21889190ca2810137ee6fda1 (
plain)
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
|
/* The reason I gave up on this:
* I thought I'd need to somehow track the first "node", so I wanted to
* experiment on a more naive implementation. I don't.
* Also, the dumb algorithm is still by far fast enough. So, Python it is. */
#include <cstdio>
#include <vector>
using namespace std;
struct CNode
{
size_t id;
CNode *prev = NULL, *next = NULL;
};
struct Circular
{
vector<CNode> nodes;
Circular(size_t size) {
for (size_t i = 0; i < size; i++) {
nodes.push_back(CNode{i});
}
// pointers to stuff in a vector? how risque!
for (size_t i = 0; i < size - 1; i++) {
nodes[i].next = &nodes[i+1];
nodes[i+1].prev = &nodes[i];
}
CNode *f = &nodes.front();
CNode *b = &nodes.back();
f->prev = b;
b->next = f;
}
void print() {
}
};
int
main()
{
int n;
vector<int> input;
while (scanf("%d ", &n) == 1) {
input.push_back(n);
}
Circular c(input.size());
}
|