#include"stdio.h"
#include"iostream.h"
typedef int elementype;
#define MAXSIZE 100
struct list
{
elementype *elem;
int length;
int listsize;
};
//建立链表
int initlist(list *l)
{
int i=0,x;
l->elem=(elementype *)malloc(sizeof(elementype));
if(!l->elem)
{
cout<<"建立链表失败"<
}
l->length=0;
l->listsize=MAXSIZE;
while(1)
{
cout<<"请输入链表数据:";
cin>>x;
if(x==0) break;
l->elem[i]=x;
l->length++;
i++;
}
return 1;
}
int swaplist(list *l)
{
int i=0,k,t;
k=(int)(l->length/2);
for(i=0;i
t=l->elem[i];
l->elem[i]=l->elem[l->length-1-i] ;
l->elem[l->length-1-i]=t;
}
return 1;
}
int displaylist(list *l)
{
int i=0;
cout<<"链表数据为:"<
{
cout<
}
cout<
int main()
{
list *l;
initlist(l);
displaylist(l);
swaplist(l);
displaylist(l);
return 1;
}