#include #include #include #include #include #include using namespace std ; #include #include "IntFamily.h" #include "ParseFamily.h" #include "GTNode.h" #define FAMSLOTS 1000000 main(int argc, char *argv[]) { vector *parsedFamilies ; if (argc==1) parsedFamilies = ParseFamily(&cin) ; else { ifstream myFInput(argv[1]) ; if (myFInput.bad()) { cerr << "Unable to open " << argv[1] << endl ; exit(1) ; } parsedFamilies = ParseFamily(&myFInput) ; myFInput.close() ; } // Originally this was allocated on the stack // However, that made MS/Windows unhappy GTNode **IntPeople = new GTNode *[FAMSLOTS] ; for (int i=0; i *)NULL; // Create the first born IntPeople[1] = new GTNode(1) ; vector::iterator ptrFamily ; for (ptrFamily = parsedFamilies->begin() ; ptrFamily != parsedFamilies->end() ; ++ptrFamily ) { // Get the node for the parent int intParent = ptrFamily->getParent() ; GTNode *nodeParent = IntPeople[intParent] ; // Create the nodes for the children int numChildren = ptrFamily->getSize() ; for (int i=numChildren-1; i>=0; --i) { int intChild = ptrFamily->getChild(i) ; IntPeople[intChild] = new GTNode(intChild) ; nodeParent->insert_first(IntPeople[intChild]) ; } } delete parsedFamilies ; // Print the ancestry for (int i=0; i *nodePres = IntPeople[i] ; while (nodePres->parent() != NULL) { cout << nodePres->value() << " <- " ; nodePres = nodePres->parent() ; } cout << nodePres->value() << endl ; } }