这个程序要错应该是错在MAIN函数里面,看一下吧…………
#include <stdio.h>
#include <conio.h>
#define MAXSIZE 60
typedef struct node
{
int data;
int next;
}SLKNODE,SLKLIST[MAXSIZE];
void init(SLKLIST s)
{
int i;
for(i=0;i<MAXSIZE-1;i++) s.next=i+1;
s[MAXSIZE-1].next=0;
}
int mymalloc(SLKLIST s)
{
int i;
i=s[0].next;
if(i) s[0].next=s.next;
return i;
}
void myfree(SLKLIST s,int i)
{
s.next=s[0].next;
s[0].next=i;
}
int insort(SLKLIST s)
{
int head,p,q,r,item;
init(s);
scanf('%d',&item);
p=mymalloc(s);
if(p) head=p;
else {s[p].data=item;s[p].next=0;}
while(1)
{
scanf('%d',&item);
if(!item) break;
r=mymalloc(s);
if(!r)
{
printf('full,no more space\n');
return r;
}
s[r].data=item;
if(item<s[head].data) {s[r].next=head; head=r;}
else
{
p=head;
while(p&&item>s[p].data)
{ q=p; p=s[q].next=r; }
}
}
return head;
}
void main()
{
int head;
SLKLIST s;
head=insort(SLKLIST s);
printf('%d',head);
}