#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node *left;
struct node *right;
};
typedef struct node node;
node* newNode(int data) {
node
* node
= malloc(sizeof(node
)); node->data = data;
node->left = NULL;
node->right = NULL;
return node;
}
void ImprimePreOrdemAux(node* arv, int nivel) {
if(arv!=NULL) {
if (nivel != 0) {
}
ImprimePreOrdemAux(arv->left, nivel + 1);
ImprimePreOrdemAux(arv->right, nivel + 1);
}
}
void ImprimePreOrdem(node* arv) {
ImprimePreOrdemAux(arv, 0);
}
int main(){
node *root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
ImprimePreOrdem(root);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnN0cnVjdCBub2RlIHsKICAgIGludCBkYXRhOwogICAgc3RydWN0IG5vZGUgKmxlZnQ7CiAgICBzdHJ1Y3Qgbm9kZSAqcmlnaHQ7Cn07Cgp0eXBlZGVmIHN0cnVjdCBub2RlIG5vZGU7CgoKbm9kZSogbmV3Tm9kZShpbnQgZGF0YSkgewogICAgbm9kZSogbm9kZSA9IG1hbGxvYyhzaXplb2Yobm9kZSkpOwogICAgbm9kZS0+ZGF0YSA9IGRhdGE7CiAgICBub2RlLT5sZWZ0ID0gTlVMTDsKICAgIG5vZGUtPnJpZ2h0ID0gTlVMTDsKICAgIHJldHVybiBub2RlOwp9Cgp2b2lkIEltcHJpbWVQcmVPcmRlbUF1eChub2RlKiBhcnYsIGludCBuaXZlbCkgewogICAgaWYoYXJ2IT1OVUxMKSB7CiAgICAgICAgaWYgKG5pdmVsICE9IDApIHsKICAgICAgICAgICAgcHJpbnRmKCItIik7CiAgICAgICAgfQogICAgICAgIHByaW50ZigiJWQiLGFydi0+ZGF0YSk7CiAgICAgICAgSW1wcmltZVByZU9yZGVtQXV4KGFydi0+bGVmdCwgbml2ZWwgKyAxKTsKICAgICAgICBJbXByaW1lUHJlT3JkZW1BdXgoYXJ2LT5yaWdodC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