[python-users] Geschachtelte Listen
Dirk Hünniger
dirk.hunniger at googlemail.com
Di Jun 25 22:55:34 CEST 2019
Hallo Klaus,
ich habe dann mal die Pointer Arithmetik veranstaltet. 306 MByte
Speicherverbrauch. Beliebig schachtelbar. Als Physiker mache ich
natürlich "relative" Pointer.
Ausgabe:
[1,2,[3,4,],3,4,]
[[1,2,3,4,5,6,7,8,9,[11,12,13,14,15,16,17,18,19,[21,22,23,24,25,26,27,28,29,[31,32,33,34,35,36,37,38,39,[41,42,43,44,45,46,47,48,49,[51,52,53,54,55,56,57,58,59,[61,62,63,64,65,66,67,68,69,[71,72,73,74,75,76,77,78,79,[81,82,83,84,85,86,87,88,89,[91,92,93,94,95,96,97,98,99,],],],],],],],],],],]
Viele Grüße Dirk
PS: Der Quelltext:
#include <iostream>
#include <vector>
#include <iostream>
using namespace std;
union NodeUnion
{
public:
int32_t n;
int32_t c;
};
class Node {
public:
bool isLeaf;
NodeUnion u;
};
class Rose {
public:
vector<Node> *v;
vector<int> current;
Rose() {
v=new vector<Node>();
Node n;
n.isLeaf=false;
v->push_back(n);
current.push_back(&(v->back())-&(v->front()));
(current.back()+&(v->front()))->u.n=current.back();
}
void pushChar(char c) {
Node n;
n.isLeaf=true;
n.u.c=c;
v->push_back(n);
(current.back()+&(v->front()))->u.n++;
}
void pushNode() {
Node n;
n.isLeaf=false;
v->push_back(n);
(current.back()+&(v->front()))->u.n++;
current.push_back(&(v->back())-&(v->front()));
(current.back()+&(v->front()))->u.n=&(v->back())-&(v->front());
}
void print(int current_print) {
cout << "[";
int current_iter=current_print;
while ((current_iter-1)!=(current_print+&(v->front()))->u.n) {
if (current_iter!=current_print) {
Node *n=current_iter+ &(v->front());
if (n->isLeaf) {
cout << n->u.c;
}
else {
print(current_iter);
}
cout << ",";
}
current_iter++;
}
cout << "]";
};
};
int main()
{
Rose rr;
rr.pushChar(1);
rr.pushChar(2);
rr.pushNode();
rr.pushChar(3);
rr.pushChar(4);
rr.current.pop_back();
rr.pushChar(5);
rr.pushChar(6);
rr.print(rr.current.front());
cout << endl;
Rose r;
for (long i=0;i<100; i++) {
if ((i%10)!=0) {
r.pushChar(i%256);
}
else {
r.pushNode();
}
}
r.print(r.current.front());
//cout << "Hello, World!";
Rose rx;
for (long i=0;i<40100100; i++) {
if ((i%1000)!=0) {
rx.pushChar(i%256);
}
else {
rx.pushNode();
}
}
cin.get();
return 0;
}
Mehr Informationen über die Mailingliste python-users