我改了一点 可以通过了
/*
HELLO.C -- Hello, world */
#include "stdio.h"
#include "alloc.h"
#include "stdlib.h"
#define LEN sizeof(struct node)
#define num 10
typedef int elemtype;
struct node
{
elemtype data;
struct node* next;
};
struct node* InitList()/**链表初始化函数**/
{
struct node* head=(struct node*)malloc(LEN);
if(head==NULL)
{
printf("Memory allocation failure.\n");
exit(1);
}
head->next=NULL;
return (head);
};
int Insert(struct node* head,int i,elemtype x)
/**把元素x插入i位置处**/
{
struct node* p=head;
struct node* newp;
int count=0;
if(i<1)
{
printf("Argyment error out of range!\n");
return(0);
}
while((p!=NULL)&&(count<i-1))
{
p=p->next;
count++;
}
if(p==NULL)
{
printf("The length of the linked list is less than %d\n",i-1);
return(0);
}
newp=(struct node*)malloc(LEN);
if(newp==NULL)
{
printf("Memory allocation failure.\n");
return(0);
}
newp->data=x;
newp->next=p->next;
p->next=newp;
return(1);
}
void Traverse(struct node* head)/**线性链表遍历函数**/
{
struct node* p=head->next;
while(p!=NULL)
{
printf("%d",p->data);
p=p->next;
}
}
void create (struct node* head)/**创建线性表 其中存放一些数**/
{
int i,j;
for(i=1;i<=num;i++)
{
j=rand();/**调用产生函数**/
Insert(head,i,j);
}
}
void reverse (struct node* head)
?
struct node* cp=head->next;
struct node* pp=NULL;
struct node* np;
while(cp!=NULL)
{
np=cp->next;
cp->next=pp;
pp=cp;
cp=np;
}
head->next==pp;
}
void main(){
int i=1;
struct node* h;
h=InitList();
while(i!=0)
{
printf("\n
Linked List Example
\n");
printf("1.Create 10 random number;\n");
printf("2.Reverse the linked List;\n");
printf("3.Traverse the linked LIst:\n");
printf("0.Exit the program.\n");
printf("Please input your selection(0-3):");
scanf("%d",&i);
swich(i)
{
case 0:exit(0);
case 1:create(h);break:
case 2:reverse(h);break;
case 3:Traverse(h);break;
default:printf("input error!please slect again!");
}
}
}