我试图用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