gentree.h

Go to the documentation of this file.
00001 #ifndef GENTREE_H
00002 #define GENTREE_H
00003 
00004 #include <iostream.h>
00005 #include <fstream.h>
00006 #include <string>
00007 
00008 // count the leading space
00009 int leadingspace(const string &s);
00010 
00011 struct node {
00012                 node() : data(), child(0), sibling(0), parent(this) {}
00013                 node(const string &name) : child(0), sibling(0), parent(this) { 
00014                         data=name; }
00015                 node(const string &name, node *p) : child(0), sibling(0) {
00016                         data = name; parent=p; }
00017 
00018                 void add_child(const string &s);
00019                 void add_sibling(const string &s);
00020 
00021                 string data;   // data stored in this node
00022                 node *child;   // left child
00023                 node *sibling; // righ sibling
00024                 node *parent;
00025 };
00026 
00027 void preorder(node *n);
00028 void levelorder(node *n);
00029 void postorder(node *n);
00030 void deltree();  // postorder traversal
00031 
00032 class gentree {
00033         public:
00034                 gentree();
00035                 gentree(const string &name);
00036                 int read(istream &ins);
00037                 ~gentree();
00038                 void showPreorder() { preorder(root); }
00039                 void showPostorder() { postorder(root); }
00040                 void showLevelorder() { levelorder(root); }
00041                 void showAsTable(ostream &os) const;
00042                 void showAsObject(ostream &os) const;
00043 
00044         private:
00045                 node *root;
00046                 static const int step;  // number of space for child
00047 };
00048 
00049 #endif

Generated on Wed Aug 10 11:56:50 2011 for Softwares from Orpara by  doxygen 1.5.6