這是我爲鏈接列表編寫的代碼。基本上它只需要輸入並打印它。在編譯時,它不會給出錯誤,但它也不會輸出。我沒有得到這個代碼有什麼問題?幫幫我。打印鏈接列表中沒有輸出
#include<stdio.h>
struct list {
int data;
struct list* next;
};
insert(struct list* node, int data)
{
node = malloc(sizeof(struct list*));
if (node == NULL)
node = data;
else
node->data = data;
node->next = NULL;
return node;
}
printlist(struct list* node)
{
if (node == NULL)
printf("Empty list\n");
while(node->next != NULL)
printf("the list contains %d", node->data);
node = node->next;
}
main()
{
struct list* NODE;
NODE = malloc(sizeof(struct list*));
insert(NODE, 3);
insert(NODE, 5);
printlist(NODE);
}
+1您指出的第一個錯誤也出現在main()中,第二個'node = data; // insert()'函數中的不兼容類型(也加上這2點),我的回答不完整,因此刪除。 –