Try this ... hope helps
Nodelist *Preorder(treeNode *node, Nodelist ** tail) { // use name 'tail' instead of 'head' because you are inserting on the tail, but this functions returns head..
Nodelist *head;
if(node==NULL){
return;
}
//printf("%d\n", node->data);
head = List_insert(tail, node->data);
Preorder(node->left, tail);
Preorder(node->right, tail);
return head;
}
Nodelist * List_insert(Nodelist ** tail, int v)
{
Nodelist * p = Node_construct(v);
p->depth = 2222;
p->next = NULL;
if (!tail) {
*tail = p; // (*tail) is NULL, true when first time List_Insert called
}
else {
(*tail)->next = p;
}
return p;
}
int main(int argc, char**argv) {
treeNode *root = NULL;
root = Insert(root, 14);
root = Insert(root, 15);
root = Insert(root, 4);
root = Insert(root, 9);
root = Insert(root, 7);
root = Insert(root, 18);
root = Insert(root, 3);
root = Insert(root, 5);
root = Insert(root, 16);
root = Insert(root, 20);
root = Insert(root, 17);
Nodelist * head = NULL;
head = Preorder(root, &head);
List_print(head);
return 0;
}