运行的时候怎么样一下运行正确一下又错误呢?
#include <stdio.h>
#define NULL 0
typedef struct DuLNode
{
int date;
struct DuLNode *prior;
struct DuLNode *next;
}DuLNode;
void InitNode(DuLNode *L)
{
L->prior=L->next=NULL;
L->date=NULL;
}
void PrintList(DuLNode *L)
{
while(L)
{
printf(" %d",L->date);
L=L->next;
}
}
void CreatList(DuLNode *L,int m)
{
DuLNode *S,*T; int i;
T=L;
scanf("%d",&T->date);
for(i=2;i<=m;i++)
{
S=(DuLNode *)malloc(sizeof(DuLNode));
InitNode(S);
scanf("%d",&S->date);
S->prior=T;
T->next=S;
T=S;
}
}
void InsertSort(DuLNode *L)
{
int u; DuLNode *T,*M; T=L;
while(T->next)
{
if(T->next->date<T->date)
{
M=T->next;
u=T->next->date;
T->next->date=T->date;
T=T->prior;
while(u<T->date)
{
T->next->date=T->date;
T=T->prior;
}
T->next->date=u; T=M;
}
else T=T->next;
}
}
main()
{
int n; DuLNode *P;
P=(DuLNode *)malloc(sizeof(DuLNode));
P->prior=P;P->next=NULL;
puts("Please input the numbers:\n");
scanf("%d",&n);
puts("Please input the elements one by one:\n");
CreatList(P,n);
puts("the sequence you input is:\n");
PrintList(P);
puts("\nThe sequence after insert_sort is:\n");
InsertSort(P);
PrintList(P);
puts("\nPress any key to quit....");
getch();
}