int main() { /*int treeCount = GetSubnetCount();*/ switchADT swList[swCount]; int actualCount = GetSWListFromFile("switch.ini", swList, swCount); PtrToTreeNode *trees = malloc(sizeof(PtrToTreeNode) * actualCount); int i; for (i = 0; i < actualCount; i++) { trees[i] = NewTreeNode(); SetTreeElement(trees[i], swList[i]); if (swList[i] -> fatherIndex != -1) { AddFirstChild(trees[i], trees[swList[i] -> fatherIndex]); } if (swList[i] -> leftIndex != -1) { AddBrother(trees[i], trees[swList[i] -> leftIndex]); } } preorder(trees[0], visitSwitch); printf("---------------------------------\n"); postorder(trees[0], visitSwitch); return EXIT_SUCCESS; }
treeNode TopDownTree(long item, unsigned depth) { if (depth > 0) { treeNode ret, l, r; ret = l = r = NULL; GGC_PUSH_3(ret, l, r); ret = NewTreeNode(NULL, NULL, item); l = TopDownTree(2 * item - 1, depth - 1); r = TopDownTree(2 * item, depth - 1); GGC_WP(ret, left, l); GGC_WP(ret, right, r); return ret; } else return NewTreeNode(NULL, NULL, item); } /* BottomUpTree() */
} temp->data = data; temp->right = NULL; temp->left = NULL; temp->parent = NULL; return temp; }