#include "stdio.h"
#include "stdlib.h"
#define ELEM struct elemtype
#define SIZE sizeof(ELEM)
ELEM{
int date;
ELEM *next;
};
void init(ELEM **head)
{
if(((*head)=(ELEM *)malloc(SIZE))==NULL)
{printf("the allcation is unsuccessful\n");}
(*head)->next=NULL;
}
void insert(ELEM *head,int i,int e)
{
int j=0;
ELEM *p,*q;
q=(ELEM *)malloc(SIZE);
for(p=head;j<i-1;j++)
p=p->next;
q->date=e;
q->next=p->next;
p->next=q;
}
main()
{
ELEM *h1;
int i,j,e;
init(&h1);
for(i=0;i<=5;i++)
insert(h1,i+1,i+3);
for(h1=h1->next;h1->next!=NULL;h1=h1->next)
printf("%8d",h1->date);
printf("\n");printf("please input the initial numbers -1 to stop\n");
scanf("%d",&j,&e);
while(j!=-1)
{
insert(h1,j,e);
scanf("%d%d",&j,&e);
for(h1=h1->next;h1->next!=NULL;h1=h1->next)
printf("%8d",h1->date);
}/*
*/
}
我不晓得为什么会内存不能读,大家指点一下