Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <Windows.h>
- using namespace std;
- class bitlist {
- public:
- unsigned long long size;
- unsigned long long bytecount;
- byte* masterlist;
- unsigned long long index;
- bitlist() :index{ 0 }, masterlist{ new byte[1]{0} }, size{ 0 }, bytecount{ 1 } {}
- ~bitlist() {
- if (masterlist) {
- delete[] masterlist;
- }
- }
- void Realloc(unsigned long long ull) {
- size_t newb = ull % 8 ? (ull >> 3) + 2 : (ull >> 3)+1;
- byte* m = new byte[newb]{};
- memcpy(m, masterlist, bytecount);
- delete[] masterlist;
- masterlist = m;
- bytecount = newb ;
- size = ull;
- }
- bitlist& operator[](unsigned long long ull) {
- if (ull > bytecount<<3) { Realloc(ull + 1); }
- else if (ull > size) { size = ull + 1; }
- index = ull;
- return *this;
- }
- bool operator==(bool b) {
- return check(masterlist[index >> 3]);
- }
- bool operator!=(bool b) {
- return !check(masterlist[index >> 3]);
- }
- void operator=(bool b) {
- set(masterlist[index>>3], b);
- }
- bool check(const byte& b) { // bitwise intensifies
- if (b & 1 << (index % 8)) { return true; }
- return false;
- }
- void set(byte& b, bool a) {
- if (a) {
- b |= 1 << (index % 8);
- }
- else if (check(b)){
- b -= 1 << (index % 8);
- }
- }
- void print() {
- for (auto i = 0; i < size; i++) {
- index = i;
- cout << check(masterlist[index>>3]) << " ";
- }
- }
- void printNumbers() {
- for (auto i = 0; i < size; i++) {
- index = i;
- if(check(masterlist[index >> 3]) )
- cout << index<< " ";
- }
- }
- };
- class node {
- public:
- node* prev;
- node* next;
- node* current;
- unsigned long long root;
- unsigned long long num;
- node() :root{ 0 }, current { this }, prev{ nullptr }, next{ nullptr }, num{ 0 }{}
- node(unsigned long long num = 0, unsigned long long root = 0, node* prev = nullptr, node* next = nullptr) :root{ root }, current { this }, prev{ prev }, next{ next }, num{ num }{}
- node(node* prev) :root{ 0 }, current { this }, num{ 0 }, prev{ prev }, next{ nullptr }{}
- };
- unsigned long long xPlusOne(unsigned long long ull) {
- if (ull & 1) { return (ull * 3) + 1; } //0dd
- return ull >> 1; //bitwise operations... beastmode unlocked
- }
- node* FindNode(const vector<node>& t, unsigned long long ull) {
- for (auto i = 0; i < t.size(); i++) {
- if (t[i].num == ull) {
- return t[i].current;
- }
- }
- return nullptr;
- }
- int main() {
- unsigned long long in{};
- bitlist bl;
- vector<node> tree{};
- for (auto i = 1; i < 10; i++) {
- in = i;
- tree.emplace_back(i, i); //makes root node
- bl[in] = true;
- while (true) {
- in = xPlusOne(in); //plucks a number
- if (bl[in] == true) { //if the number is already in the tree it is disregarded
- break;
- }
- tree.emplace_back(in, i, &tree[tree.size() - 1]); //new branch node is made
- tree[tree.size() - 2].next = &tree[tree.size() - 1]; // attach new node to the last
- bl[in] = true; // updates the list of which numbers have been touched already.
- }
- }
- //bl.printNumbers();
- for (auto& n : tree) {
- cout << "num = " << n.num << " prev = " << n.prev << " current = " << n.current << " next = " << n.next << " root= " << n.root << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment