请大虾们帮帮忙 谢谢
#include <stdio.h>#include <stdlib.h>
#define MAX 10
struct List
{
int Number;
int Total;
struct List *Next;
};
typedef struct List Node;
typedef Node *Link;
int Data[2][MAX] = { 1, 3, 5, 7, 2, 6, 8, 9, 0, 4,
15,35,10,67,25,65,38,70,30,20};
/* Create List */
Link Create_List( Link Head )
{
Link Pointer;
Link New;
int i;
Head = ( Link ) malloc( sizeof( Node ) );
if( Head == NULL )
{
printf("Memory allocate fainure!!\n");
}
else
{
Head->Number = Data[0][0];
Head->Total = Data[1][0];
Head->Next = NULL;
Pointer = Head;
for( i =1; i < MAX; i ++)
{
New = ( Link ) malloc( sizeof( Node ) );
New->Number = Data[0][i];
New->Total = Data[1][i];
New->Next = NULL;
Pointer->Next = New;
Pointer = New;
}
}
return Head;
}
/* Insert List */
Link Insert_List( Link Head, Link New, int Key )
{
Link Pointer;
Pointer = Head;
while( 1 )
{
if( Pointer == NULL )
{
New->Next = Head;
Head = New;
break;
}
if( Pointer->Next == Key )
{
New->Next = Pointer->Next;
Pointer->Next = New;
break;
}
Pointer = Pointer->Next;
}
return Head;
}
/* Print List */
void Print_List( Link Head )
{
Link Pointer;
Pointer = Head;
while( Pointer != NULL )
{
printf("[%d,%d]" , Pointer->Number, Pointer->Total);
Pointer = Pointer->Next;
}
printf("\n");
}
/* Free List */
void Free_List( Link Head )
{
Link Pointer;
while( Head != NULL )
{
Pointer = Head;
Head = Head->Next;
free( Pointer );
}
}
int main()
{
Link Head;
Link New;
int Key;
Head = Create_List( Head );
if( Head != NULL )
{
Print_List( Head );
while( 1 )
{
printf("Input 0 to Exit\n");
New = ( Link ) malloc( sizeof( Node ) );
printf("please input the data number : ");
scanf("%d",&New->Number);
if( New->Number == 0 )
break;
printf("Please input the data total : ");
scanf("%d" , &New->Total) ;
printf("please input the data number for insert");
scanf("%d" , &Key);
Head = Insert_List( Head, New, Key );
Print_List( Head );
}
Free_List( Head );
}
getch();
}
为什么程序运行不正常?
win-tc编的
输出里有两个警告
不可移动的指针(地址常数)比较在Insert_List 函数中
可能在'Head'定义之前使用了他在main()函数中