我在C中的链表的插入方法遇到了一些麻烦.它似乎只在列表的开头添加.我做的任何其他插入都失败了.而这个CodeBlocks调试器很难理解我仍然没有得到它.它永远不会给我价值,只有内存中的地址.无论如何这是我的功能.你有没有看到它失败的原因?
/* 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){
head->next = newNode;
printf("added at beginning\n");
}
else
{
//else loop through the list and find the last
//node, insert next to it
node *current = head;
while(current->next != NULL) …Run Code Online (Sandbox Code Playgroud)