Dewey1040 7 Junior Poster

Can anybody help me understand how this design pattern works? I'm supposed to make a program that will create a tree using pointers or an array. The client is then supposed to choose which of the two types of trees he wants to use... I've created the tree with pointers, but I don't understand how to extend that and create an array option. I can figure out how to create a tree with an array... just not the bridge aspect. I'll supply the tree.h file to help understand what my program looks like and does.

#ifndef TREE_H
#define TREE_H

#include <string>
#include <iostream>
#include <stdexcept>
using namespace std;

class Node{

public:
  Node();
  Node& next() const;          //return right sibling
  Node& getLc() const;         //return left child
  
  void insertLeft( Node*, int*, int );  //insert a new node to left child
  void insertRight( Node*, int*, int ); //insert a new node to right sibling

  void nullLeft();             //make leftchild pointer = NULL
  void nullRight();            //make rightsibling pointer = NULL
  void setLabel( int* );     //set label
  void setSize( int );

  int* getLabel();           //get label
  int getSize();

private:

  int *label;           // node holds an int array
  int sizeOfLabel;
  Node *leftchild;      // a pointer to its child (left pointer)
  Node *rightsibling;   // a pointer to its sibling (right pointer)
};

class Tree{

public:
  Tree( int* , int, int );    //constructor
  Node& getRoot() const;      //get the root node
  Node& findNode( int* );     //find specific node
  bool isFull();         //return true if # of nodes = full, false otherwise  

  void annotate( int*, int, Node& );  //annotate specific node with given int*
  void add( int*, int, Node&, Node&, Node* );  //add new node

  void preOrder() const;                    //print tree in preOrder
  void postOrder() const;                   //print tree in postOrder

  int numberOfNodes() const;                //return # of nodes
  int height() const;                       //return height
  int leaves() const;                       //return # of leaves
private:
  Node* root;           //root node
  int full;             //max size of tree
};

Node& findHelp( Node&, int*, int);
                                   // recursive helper functions
void preHelp( Node& );
void postHelp( Node& ); 
void printHelp( int*, int );

int betterMatch( Node&, int*, int );
int nodeCount( Node&, int i );
int heightHelp( Node&, int i );
int leafHelp( Node&, int i );
#endif
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.