编译调试无问题,运行出错,求大神指点啊!
程序代码:#include<stdio.h>
#include<stdlib.h>
struct node *LinkListCreate();
struct node *BubbleSort(struct node *Header);
void print(struct node *Header);
struct node
{
long int data;
struct node *next;
};
int main()
{
struct node *Header;
Header = LinkListCreate();
Header = BubbleSort(Header);
print(Header);
return 0;
}
struct node *LinkListCreate()
{
struct node *Header = NULL;
struct node *p1, *p2;
int n = 0;
char *string,*stopstring;
p1 = (struct node *)malloc(sizeof(struct node));
printf("Please input an integer number:\n");
scanf("%s",string); //实际输入当作字符串处理 这里出问题了,说string未初始化,但是不知道是怎么回事
p1->data = strtol(string,&stopstring,10);
p2 = p1;
while (('q' != *stopstring)||('Q' != *stopstring))
{
n = n + 1;
if (1 ==n)
Header = p1;
else
p2->next = p1;
p2 = p1;
p1 = (struct node *)malloc(sizeof(struct node));
printf("Please input an integer number:\n");
scanf("%s",string);
}
p2->next = NULL;
return (Header);
}
struct node *BubbleSort(struct node *Header)
{
struct node *p1,*p2;
long int temp;
if (NULL == Header)
{
printf("The linked list is Null!");
return Header;
}
for (p1 = Header; NULL != p1->next;p1++)
{
for (p2 = p1->next;NULL != p2;p2++)
{
if (p1->data < p2->data)
{
temp = p1->data;
p1->data = p2->data;
p2->data = temp;
}
}
Header = p1;
}
return (Header);
}
void print(struct node *Header)
{
struct node *p;
printf("The sorted number is:\n");
p = Header;
if (NULL != Header)
do
{
printf("%ld ",p->data);
p = p->next;
}while (NULL != p);
}
求大神指点啊!









