MESSAGE
DATE | 2016-11-17 |
FROM | Ruben Safir
|
SUBJECT | Re: [Hangout-NYLXS] at K&R now
|
On 11/17/2016 07:34 PM, Ruben Safir wrote: > anyone else dropping in at te Kilarny Rose? > We are set up downstairs near the power > > Ruben > so in the end, we were perplexed with the simple problem of mapping an array of random numbers into a binary tree
so here is an array of random numbers
using namespace std;
int *data = new int[SIZE]; // int *cache = new int[SIZE]; struct timespec now; clock_gettime(CLOCK_REALTIME, &now); long seed = now.tv_nsec; srand( (unsigned int) seed); for(int i = 0; i < SIZE; i++){ data[i] = rand() % 1000000; cout << data[i] << "\t"; } cout << endl;
make a node class Node { public:
/* ==================== LIFECYCLE ======================================= */ Node (): _parent{nullptr}, _left{nullptr}, _right{nullptr}{}; /* constructor */ Node (Node * par): _parent{par}, _left{nullptr}, _right{nullptr}{}; /* constructor */ Node ( const Node &other ); /* copy constructor */ ~Node (); /* destructor */
/* ==================== ACCESSORS ======================================= */ Node * parent(){ retun _parent; } Node * left() const{ return _left; } Node * right() const{ return _right; } int value() const{ return _value; } int max() const{ return _max; } Node * parent(Node * in){ _parent = in; return _parent; } Node * left(Node * in){ _left = in; return _left; } Node * right(Node *in){ _right = in; return _right; } int value(int in){ _value = in; return _value; } int max(int in){ _max = in; return _max; }
/* ==================== MUTATORS ======================================= */
/* ==================== OPERATORS ======================================= */
const Node& operator = ( const Node &other ){ left(other.left()); right(other.right()); value(other.value()); max(other.max()); return * this; }; /* assignment operator */
/* ==================== DATA MEMBERS ======================================= */ protected:
private: Node *_parent; Node *_left; Node *_right; int _value; int _max; }; /* ----- end of class Node ----- */
now how you you build the tree. We tried a few mothods and nothing shook out
-- So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive http://www.coinhangout.com - coins! http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps, but incompatible with living as a free human being. -RI Safir 2013 _______________________________________________ hangout mailing list hangout-at-nylxs.com http://www.nylxs.com/
|
|