Ejemplo n.º 1
0
void BinarySearchTree::printPre(Node *node)
{
	if(node == NULL)
		return;
	
	cout<<node->getValue()<<" ";
	printPre(node->getLeft());
	printPre(node->getRight());
}
Ejemplo n.º 2
0
void AVL_tree<T>::printPre(Node_T *p) {
    if(!p)  return;
    printElem(p);
    cout << "{";
    if(p->m_pChildren[0])   printPre(p->m_pChildren[0]);
    cout << ", ";
    if(p->m_pChildren[1])   printPre(p->m_pChildren[1]);
    cout << "} ";
}
Ejemplo n.º 3
0
// Går ner till vänster först.
// https://en.wikipedia.org/wiki/Tree_traversal
void printPre(Node* node)
{
	if (node != NULL)
	{
		printf("%d\n", node->value);
		printPre(node->left);
		printPre(node->right);
	}
}
Ejemplo n.º 4
0
inline void casadi_math<T>::print(unsigned char op, std::ostream &stream, const std::string& x, const std::string& y){
  if(ndeps(op)==2){
    printPre(op,stream);
    stream << x;
    printSep(op,stream);
    stream << y;
    printPost(op,stream);
  } else {
    printPre(op,stream);
    stream << x;
    printPost(op,stream);
  }
}
void printPre (int s, int e, int root) {
    if (s > e) return;
    int n = e - s + 1;
    int l = log(n + 1) / log(2);
    int temp = n - pow(2, l) + 1;
    int rn = 0;
    if (temp <= pow(2, l - 1)) {
        rn = pow(2, l - 1) - 1;
    } else {
        rn = n - pow(2, l);
    }
    printPre(s, e - rn - 1, 2 * root + 1);
    printPre(e - rn + 1, e, 2 * root + 2);
    level[root] = inorder[e - rn];
}
Ejemplo n.º 6
0
void Disp::output(uint64_t bits)
{
    printPre(bits);
    cout << _name;
    if (S_ISDIR(_type)) {
        cout << "/";
    }
    if (_fail == 1) {
        cout << "/";
    }
    cout << endl;

    if (_child == NULL) {
        return;
    }

    My570ListElem *item = NULL;
    Disp *dp = NULL;
    uint64_t subbits = bits;
    for (item = _child->First(); item != NULL; item = _child->Next(item))
    {
        dp = (Disp *)item->Obj();
        if (item == _child->Last()) {
            subbits |= 1<<dp->_level;
        }
        dp->output(subbits);
    }
}
Ejemplo n.º 7
0
void print(Tree* tree)
{
	int choice;

	do
	{

		system("cls");
		printf("1. Print preorder\n");
		printf("2. Print postorder\n");
		printf("3. Print inorder\n");
		printf("9. Back\n");
		scanf("%d", &choice);

		switch (choice)
		{
		case 1:
			system("cls");
			printf("Printing preorder...\n\n");
			printPre(tree->root);
			printf("\n");
			system("pause");
			break;
		case 2:
			system("cls");
			printf("Printing postorder...\n\n");
			printPost(tree->root);
			printf("\n");
			system("pause");
			break;
		case 3:
			system("cls");
			printf("Printing inorder...\n\n");
			printOrder(tree->root);
			printf("\n");
			system("pause");
			break;
		case 9:
			break;
		default:
			printf("Your choice was out of range!\n");
			system("pause");
			break;
		}
	} while ((choice > 3 || choice < 1) && choice != 9);

}
int main () {
    int n = 0;
    scanf("%d", &n);
    inorder = new int[n], level = new int[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &inorder[i]);
    }
    qsort(inorder, n, sizeof(inorder[0]), [](const void *a, const void *b){
        int arg1 = *static_cast<const int *>(a);
        int arg2 = *static_cast<const int *>(b);
        
        if (arg1 > arg2) return 1;
        if (arg2 > arg1) return -1;
        return 0;
    });
    printPre(0, n - 1, 0);
    printf("%d", level[0]);
    for (int i = 1; i < n; i++) {
        printf(" %d", level[i]);
    }
    delete [] inorder;
    delete [] level;
    return 0;
}
Ejemplo n.º 9
0
void BinTree<T>::printPre() {
    printPre(m_pRoot);
    cout << endl;
}
Ejemplo n.º 10
0
void AVL_tree<T>::printPre() {
    printPre(m_pRoot);
    cout << endl;
}
Ejemplo n.º 11
0
void BinarySearchTree::printPre()
{
	printPre(root);
	cout << endl;
}