我試圖用c語言遞歸創建線性鏈表, 但是從這裏繼續粘住,並且代碼不能處理錯誤「Linker Tools Error LNK2019」。可悲的是我不明白髮生了什麼事。這是我的代碼。用C語言創建並顯示線性鏈表(遞歸地)
感謝您提前給予的大力幫助。
#include <stdio.h>
#include <stdlib.h>
struct node
{
char num; //Data of the node
struct node *nextptr; //Address of the next node
};
typedef struct node element;
typedef element *link;
link head;
void displayList(); // function to display the list
int main()
{
char s[] = "abc";
link stol(s);
{
link head;
if (s[0] == '\0')return(NULL);
else {
head = (link)malloc(sizeof(element));
head->num = s[0];
head->nextptr = stol(s + 1);
return(head);
}
}
printf("\n\n Linked List : To create and display Singly Linked List :\n");
printf("-------------------------------------------------------------\n");
displayList();
return 0;
}
void displayList()
{
link tmp;
if (head == NULL)
{
printf(" List is empty.");
}
else
{
tmp = head;
while (tmp != NULL)
{
printf(" Data = %d\n", tmp->num); // prints the data of current node
tmp = tmp->nextptr; // advances the position of current node
}
}
}
在'main'函數外(和之前)定義'stol'函數。 – BLUEPIXY
謝謝。你的意思是我需要把「鏈接stol」外(和之前)的主要功能? –
我的意思是喜歡[this](http://ideone.com/IHPo0I) – BLUEPIXY