Tag: 二进制树

将二叉树转换为链接列表

我正在尝试从二叉树创建链接列表。 问题是,是否可以使用简单的链表而不是双链表? 我试过这个: typedef struct arvbin* ABin; typedef struct arvbin { int value; ABin right; ABin left; } arvb; typedef struct slist { int value; struct slist* next; } *SList; void preorder(ABin tree, SList *l) { if(tree) { (*l)->value = tree->value; (*l)->next = (SList) malloc(sizeof(struct slist)); l = &((*l)->next); printf(“tese\n”); preorder(tree->left, l); preorder(tree->right, l); } […]

最后是C链表插入节点

我的插入方法在C中的链接列表时遇到了一些问题。它似乎只在列表的开头添加。 我做的任何其他插入失败。 而这个CodeBlocks调试器很难理解我仍然没有得到它。 它永远不会给我价值,只有内存中的地址。 无论如何这是我的function。 你有没有看到它失败的原因? /* function to add a new node at the end of the list */ int addNodeBottom(int val, node *head){ //create new node node *newNode = (node*)malloc(sizeof(node)); if(newNode == NULL){ fprintf(stderr, “Unable to allocate memory for new node\n”); exit(-1); } newNode->value = val; //check for first insertion if(head->next == NULL){ […]