实验1
8576 顺序线性表的基本操作
时间限制:1000MS 代码长度限制:10KB
提交次数:9027 通过次数:2456
题型: 编程题 语言: G++;GCC
Description
编写算法,创建初始化容量为LIST_INIT_SIZE的顺序表T,并实现插入、删除、遍历操作。本题目给出部分代码,请补全内容。
#include<> #include<> #define OK 1 #define ERROR 0 #define LIST_INIT_SIZE 100 #define LISTINCREMENT 10 #define ElemType int typedef struct { int *elem; int length; int listsize; }SqList; int InitList_Sq(SqList &L) { // 算法2.3,构造一个空的线性表L,该线性表预定义大小为LIST_INIT_SIZE // 请补全代码 } int Load_Sq(SqList &L) { // 输出顺序表中的所有元素 int i; if(_________________________) printf("The List is empty!"); // 请填空 else { printf("The List is: "); for(_________________________) printf("%d ",_________________________); // 请填空 } printf("\n"); return OK; } int ListInsert_Sq(SqList &L,int i,int e) { // 算法2.4,在顺序线性表L中第i个位置之前插入新的元素e // i的合法值为1≤i≤ +1 // 请补全代码 } int ListDelete_Sq(SqList &L,int i, int &e) { // 算法2.5,在顺序线性表L中删除第i个位置的元素,并用e返回其值 // i的合法值为1≤i≤ // 请补全代码 } int main() { SqList T; int a, i; ElemType e, x; if(_________________________) // 判断顺序表是否创建成功 { printf("A Sequence List Has Created.\n"); } while(1) { printf("1:Insert element\n2:Delete element\n3:Load all elements\n0:Exit\nPlease choose:\n"); scanf("%d",&a); switch(a) { case 1: scanf("%d%d",&i,&x); if(_________________________) printf("Insert Error!\n"); // 执行插入函数,根据返回值判断i值是否合法 else printf("The Element %d is Successfully Inserted!\n", x); break; case 2: scanf("%d",&i); if(_________________________) printf("Delete Error!\n"); // 执行删除函数,根据返回值判断i值是否合法 else printf("The Element %d is Successfully Deleted!\n", e); break; case 3: Load_Sq(T); break; case 0: return 1; } } }
输入格式
测试样例格式说明: 根据菜单操作: 1、输入1,表示要实现插入操作,紧跟着要输入插入的位置和元素,用空格分开 2、输入2,表示要实现删除操作,紧跟着要输入删除的位置 3、输入3,表示要输出顺序表的所有元素 4、输入0,表示程序结束
输入样例
1 1 2 1 1 3 2 1 3 0
输出样例
A Sequence List Has Created. 1:Insert element 2:Delete element 3:Load all elements 0:Exit Please choose: The Element 2 is Successfully Inserted! 1:Insert element 2:Delete element 3:Load all elements 0:Exit Please choose: The Element 3 is Successfully Inserted! 1:Insert element 2:Delete element 3:Load all elements 0:Exit Please choose: The Element 3 is Successfully Deleted! 1:Insert element 2:Delete element 3:Load all elements 0:Exit Please choose: The List is: 2 1:Insert element 2:Delete element 3:Load all elements 0:Exit Please choose:
代码
#include<>
#include<>
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define ElemType int
typedef struct
{
int *elem;
int length;
int listsize;
}SqList;
int InitList_Sq(SqList &L)
{
// 算法2.3,构造一个空的线性表L,该线性表预定义大小为LIST_INIT_SIZE
// 请补全代码
=new ElemType[LIST_INIT_SIZE];
if(!)
return(ERROR);
=0;
=LIST_INIT_SIZE;//!!!不要漏了
return OK;
}
int Load_Sq(SqList &L)
{
// 输出顺序表中的所有元素
int i;
if(==0) printf("The List is empty!"); // 请填空
else
{
printf("The List is: ");
for(i=0;i<;i++) printf("%d ",[i]); // 请填空
}
printf("\n");
return OK;
}
int ListInsert_Sq(SqList &L,int i,int e)
{
// 算法2.4,在顺序线性表L中第i个位置之前插入新的元素e
// i的合法值为1≤i≤ +1
// 请补全代码
if(i<1||i>+1)
return ERROR;
if(==LIST_INIT_SIZE)//!!!不要漏了
return ERROR;
for(int j=;j>=i;j--)
{
[j]=[j-1];
}
[i-1]=e;//第i个元素位置是[i-1]
++;
return OK;
}
int ListDelete_Sq(SqList &L,int i, int &e)
{
// 算法2.5,在顺序线性表L中删除第i个位置的元素,并用e返回其值
// i的合法值为1≤i≤
// 请补全代码
if(i<1||i>)
return ERROR;
e=[i-1];
for(int j=i-1;j<-1;j++)
{
[j]=[j+1];
}
--;
return e;
}
int main()
{
SqList T;
int a, i;
ElemType e, x;
if(InitList_Sq(T)) // 判断顺序表是否创建成功
{
printf("A Sequence List Has Created.\n");
}
while(1)
{
printf("1:Insert element\n2:Delete element\n3:Load all elements\n0:Exit\nPlease choose:\n");
scanf("%d",&a);
switch(a)
{
case 1: scanf("%d%d",&i,&x);
if(ListInsert_Sq(T,i,x)==ERROR) printf("Insert Error!\n");
// 执行插入函数,根据返回值判断i值是否合法
else printf("The Element %d is Successfully Inserted!\n", x);
break;
case 2: scanf("%d",&i);
if(ListDelete_Sq(T,i,e)==ERROR) printf("Delete Error!\n");
// 执行删除函数,根据返回值判断i值是否合法
else printf("The Element %d is Successfully Deleted!\n", e);
break;
case 3: Load_Sq(T);
break;
case 0: return 1;
}
}
}
注意点:
1.插入时和删除时的范围不同:插入时尾部可以插入,删除时尾部不能删除。
2.插入和删除循环的起点不同:插入时循环从尾部开始,删除则不是
3.要看清题目要求,删除时要求返回e,不要return ERROR/OK.
4.构造线性表时,看清题目给的是T,不要写成L。
5.插入和删除都需要先判断i是否合法。特别注意插入时若空间已满(不要漏掉这个判断),则不能插入。
6.不要漏掉=LIST_INIT_SIZE;,,表示当前分配的存储空间大小(以元素数量计),这个空间是用于存储表中元素的。
8577 合并顺序表
时间限制:1000MS 代码长度限制:10KB
提交次数:5339 通过次数:2251
题型: 编程题 语言: G++
Description
若线性表中数据元素相互之间可以比较,且数据元素在表中按值递增或递减,则称该表为有序表。 编写算法,将两个非递减有序顺序表A和B合并成一个新的非递减有序顺序表C。
输入格式
第一行:顺序表A的元素个数 第二行:顺序表A的各元素(非递减),用空格分开 第三行:顺序表B的元素个数 第四行:顺序表B的各元素(非递减),用空格分开
输出格式
第一行:顺序表A的元素列表 第二行:顺序表B的元素列表 第三行:合并后顺序表C的元素列表
输入样例
5 1 3 5 7 9 5 2 4 6 8 10
输出样例
List A:1 3 5 7 9 List B:2 4 6 8 10 List C:1 2 3 4 5 6 7 8 9 10
提示
输出时注意大小写和标点。
代码:
#include <iostream>
#define SIZE 100
#define ERROR 0
#define OK 1
#define end1 '\n'
using namespace std;
typedef struct
{
int *elem;
int length;
int listsize;
}Sqlist;
int InitSqlist(Sqlist &L)
{
=new int[SIZE];
if(!)
return ERROR;
=0;
=SIZE;
return OK;
}
int putinlist(Sqlist &L)
{
int n,i;
cin>>n;
int a;
for(i=0;i<n;i++)
{
cin>>a;
[i]=a;
++;
}
if(==n)
return OK;
else
return ERROR;
}
void MergeList(Sqlist L1,Sqlist L2,Sqlist &L3)
{
int *pa,*pb,*pc,*pa_last,*pb_last;
=+;
=new int [];
pc=;
pa=;
pb=;
pa_last=+-1;
pb_last=+-1;
while(pa<=pa_last&&pb<=pb_last)
{
if(*pa<=*pb)
{
*pc++=*pa++;
}
else
*pc++=*pb++;
}
while(pa<=pa_last)
{
*pc++=*pa++;
}
while(pb<=pb_last)
{
*pc++=*pb++;
}
}
int print(Sqlist &L)
{
int i;
for(i=0;i<;i++)
{
cout<<[i]<<" ";
}
cout<<end1;
}
int main()
{
Sqlist T1,T2,T3;
InitSqlist(T1);
InitSqlist(T2);
int n1,n2;
//cin>>n1;
putinlist(T1);
//cin>>n2;
putinlist(T2);
InitSqlist(T3);
MergeList(T1,T2,T3);
cout<<"List A:";
print(T1);
cout<<"List B:";
print(T2);
cout<<"List C:";
print(T3);
return 0;
}
8578 顺序表逆置
时间限制:1000MS 代码长度限制:10KB
提交次数:3660 通过次数:2149
题型: 编程题 语言: G++;GCC
Description
顺序表的基本操作代码如下: #include<> #include<> #define OK 1 #define ERROR 0 #define LIST_INIT_SIZE 100 #define LISTINCREMENT 10 #define ElemType int typedef int Status; typedef struct { int *elem; int length; int listsize; }SqList; Status InitList_Sq(SqList &L) { // 算法2.3 // 构造一个空的线性表L。 = (ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType)); if (!) return OK; // 存储分配失败 = 0; // 空表长度为0 = LIST_INIT_SIZE; // 初始存储容量 return OK; } // InitList_Sq Status ListInsert_Sq(SqList &L, int i, ElemType e) { // 算法2.4 // 在顺序线性表L的第i个元素之前插入新的元素e, // i的合法值为1≤i≤ListLength_Sq(L)+1 ElemType *p; if (i < 1 || i > +1) return ERROR; // i值不合法 if ( >= ) { // 当前存储空间已满,增加容量 ElemType *newbase = (ElemType *)realloc(, (+LISTINCREMENT)*sizeof (ElemType)); if (!newbase) return ERROR; // 存储分配失败 = newbase; // 新基址 += LISTINCREMENT; // 增加存储容量 } ElemType *q = &([i-1]); // q为插入位置 for (p = &([-1]); p>=q; --p) *(p+1) = *p; // 插入位置及之后的元素右移 *q = e; // 插入e ++; // 表长增1 return OK; } // ListInsert_Sq Status ListDelete_Sq(SqList &L, int i, ElemType &e) { // 算法2.5 // 在顺序线性表L中删除第i个元素,并用e返回其值。 // i的合法值为1≤i≤ListLength_Sq(L)。 ElemType *p, *q; if (i<1 || i>) return ERROR; // i值不合法 p = &([i-1]); // p为被删除元素的位置 e = *p; // 被删除元素的值赋给e q = +-1; // 表尾元素的位置 for (++p; p<=q; ++p) *(p-1) = *p; // 被删除元素之后的元素左移 --; // 表长减1 return OK; } // ListDelete_Sq 设有一顺序表A=(a0,a1,..., ai,...an-1),其逆顺序表定义为A'=( an-1,..., ai,...,a1, a0)。设计一个算法,将顺序表逆置,要求顺序表仍占用原顺序表的空间。
输入格式
第一行:输入顺序表的元素个数 第二行:输入顺序表的各元素,用空格分开
输出格式
第一行:逆置前的顺序表元素列表 第二行:逆置后的顺序表元素列表
输入样例
10 1 2 3 4 5 6 7 8 9 10
输出样例
The List is:1 2 3 4 5 6 7 8 9 10 The turned List is:10 9 8 7 6 5 4 3 2 1
代码:
#include<>
#include<>
#include<iostream>
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define ElemType int
using namespace std;
typedef struct
{
int *elem;
int length;
int listsize;
}SqList;
int InitList_Sq(SqList &L)
{
// 算法2.3,构造一个空的线性表L,该线性表预定义大小为LIST_INIT_SIZE
// 请补全代码
=new ElemType[LIST_INIT_SIZE];
if(!) return ERROR;
=0;
=LIST_INIT_SIZE;
return OK;
}
int Load_Sq(SqList &L)
{
// 输出顺序表中的所有元素
int i;
if(==0) printf("The List is empty!"); // 请填空
else
{
//printf("The List is: ");
for(i=0;i<;i++) printf("%d ",[i]); // 请填空
}
printf("\n");
return OK;
}
int putin(SqList &L)
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>[i];
++;
}
if(==n)return OK;
else return ERROR;
}
int nizhi(SqList &L)
{
int temp;
for(int i=0;i</2;i++)
{
temp=[i];
[i]=[-i-1];
[-i-1]=temp;
}
}
int main()
{
SqList T;
InitList_Sq(T);
putin(T);
cout<<"The List is:";
Load_Sq(T);
cout<<"The turned List is:";
nizhi(T);
Load_Sq(T);
return 0;
}
8579 链式线性表的基本操作
时间限制:1000MS 代码长度限制:10KB
提交次数:5567 通过次数:2176
题型: 编程题 语言: G++;GCC
Description
编写算法,创建一个含有n个元素的带头结点的单链表L并实现插入、删除、遍历操作。本题目提供部分代码,请补全内容。
#include<> #include<> #define ERROR 0 #define OK 1 #define ElemType int typedef struct LNode { int data; struct LNode *next; }LNode,*LinkList; int CreateLink_L(LinkList &L,int n){ // 创建含有n个元素的单链表 LinkList p,q; int i; ElemType e; L = new LNode; L->next = NULL; // 先建立一个带头结点的单链表 q = L; for (i=0; i<n; i++) { scanf("%d", &e); p = new LNode; // 生成新结点 // 请补全代码 } return OK; } int LoadLink_L(LinkList &L){ // 单链表遍历 LinkList p = L->next; if(___________________________)printf("The List is empty!"); // 请填空 else { printf("The LinkList is:"); while(___________________________) // 请填空 { printf("%d ",p->data); ___________________________ // 请填空 } } printf("\n"); return OK; } int LinkInsert_L(LinkList &L,int i,ElemType e){ // 算法2.9 // 在带头结点的单链线性表L中第i个位置之前插入元素e // 请补全代码 } int LinkDelete_L(LinkList &L,int i, ElemType &e){ // 算法2.10 // 在带头结点的单链线性表L中,删除第i个元素,并用e返回其值 // 请补全代码 } int main() { LinkList T; int a,n,i; ElemType x, e; printf("Please input the init size of the linklist:\n"); scanf("%d",&n); printf("Please input the %d element of the linklist:\n", n); if(___________________________) // 判断链表是否创建成功,请填空 { printf("A Link List Has Created.\n"); LoadLink_L(T); } while(1) { printf("1:Insert element\n2:Delete element\n3:Load all elements\n0:Exit\nPlease choose:\n"); scanf("%d",&a); switch(a) { case 1: scanf("%d%d",&i,&x); if(___________________________) printf("Insert Error!\n"); // 判断i值是否合法,请填空 else printf("The Element %d is Successfully Inserted!\n", x); break; case 2: scanf("%d",&i); if(___________________________) printf("Delete Error!\n"); // 判断i值是否合法,请填空 else printf("The Element %d is Successfully Deleted!\n", e); break; case 3: LoadLink_L(T); break; case 0: return 1; } } }
输入格式
测试样例格式说明: 根据菜单操作: 1、输入1,表示要实现插入操作,紧跟着要输入插入的位置和元素,用空格分开 2、输入2,表示要实现删除操作,紧跟着要输入删除的位置 3、输入3,表示要输出顺序表的所有元素 4、输入0,表示程序结束
输入样例
3 3 6 9 3 1 4 12 2 1 3 0
输出样例
Please input the init size of the linklist: Please input the 3 element of the linklist: A Link List Has Created. The LinkList is:3 6 9 1:Insert element 2:Delete element 3:Load all elements 0:Exit Please choose: The LinkList is:3 6 9 1:Insert element 2:Delete element 3:Load all elements 0:Exit Please choose: The Element 12 is Successfully Inserted! 1:Insert element 2:Delete element 3:Load all elements 0:Exit Please choose: The Element 3 is Successfully Deleted! 1:Insert element 2:Delete element 3:Load all elements 0:Exit Please choose: The LinkList is:6 9 12 1:Insert element 2:Delete element 3:Load all elements 0:Exit Please choose:
代码:
#include<>
#include<>
#define ERROR 0
#define OK 1
#define ElemType int
typedef struct LNode
{
int data;
struct LNode *next;
} LNode,*LinkList;
int CreateLink_L(LinkList &L,int n)
{
// 创建含有n个元素的单链表
LinkList p,q;//两个指针
int i;
ElemType e;
L = new LNode;
L->next = NULL;// 先建立一个带头结点的单链表
q = L;//将头指针L赋值给q,让q也指向头结点
for (i=0; i<n; i++)
{
scanf("%d", &e);
p = new LNode; // 生成新结点
p->data=e;// 将e赋值给p的数据域
p->next=NULL;//指针域指向空
q->next=p;//把q和p连起来
q=p;//q指向新的尾结点
}
return OK;
}
int LoadLink_L(LinkList &L)
{
// 单链表遍历
LinkList p = L->next;//p指向首元结点
if(!p)printf("The List is empty!"); //首元结点为空
else
{
printf("The LinkList is:");
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}
printf("\n");
return OK;
}
int LinkInsert_L(LinkList &L,int i,ElemType e)
{
// 算法2.9
// 在带头结点的单链线性表L中第i个位置之前插入元素e
// 请补全代码
LinkList p=L;//p指向头结点
LinkList s;
int j=0;
while(p&&(j<i-1))//当p指向的结点不为空且计数器j<i-1,即定位到第i个位置前
{
p=p->next;
++j;
}
if(!p||(j>i-1))
return ERROR;
s=new LNode;//找到插入位置前一个结点后,创建新结点s
s->data=e;//e赋值给s的数据域
s->next=p->next;//把p的next赋值给s, 即把p后面一个结点与s链接起来,s和p同时指向p的后一个结点
p->next=s;//p的指针域指向s
return OK;
}
int LinkDelete_L(LinkList &L,int i, ElemType &e)
{
// 算法2.10
// 在带头结点的单链线性表L中,删除第i个元素,并用e返回其值
// 请补全代码
LinkList p=L,q;
LinkList s;
int j=0;
while(p->next&&(j<i-1))
{
p=p->next;
++j;
}
if(!(p->next)||(j>i-1))
return ERROR;
q=p->next;//p定位到要删除的元素的前一个,q定位到要删除的元素
e=q->data;//把要删除的结点的数据域保存到e中
p->next=q->next;//使p的指针域指向q的next ,即p,q,同时指向q的后一个结点
delete q;
return OK;
}
int main()
{
LinkList T;
int a,n,i;
ElemType x, e;
printf("Please input the init size of the linklist:\n");
scanf("%d",&n);
printf("Please input the %d element of the linklist:\n", n);
if(CreateLink_L(T,n)) // 判断链表是否创建成功,请填空
{
printf("A Link List Has Created.\n");
LoadLink_L(T);
}
while(1)
{
printf("1:Insert element\n2:Delete element\n3:Load all elements\n0:Exit\nPlease choose:\n");
scanf("%d",&a);
switch(a)
{
case 1:
scanf("%d%d",&i,&x);
if(LinkInsert_L(T,i,x)==0) printf("Insert Error!\n"); // 判断i值是否合法,请填空
else printf("The Element %d is Successfully Inserted!\n", x);
break;
case 2:
scanf("%d",&i);
if(LinkDelete_L(T,i,e)==ERROR) printf("Delete Error!\n"); // 判断i值是否合法,请填空
else printf("The Element %d is Successfully Deleted!\n", e);
break;
case 3:
LoadLink_L(T);
break;
case 0:
return 1;
}
}
}
8580 合并链表
代码:
#include <>
#include <>
#define OK 1
#define ERROR 0
#define ElemType int
typedef int Status;
typedef struct LNode
{
int data;
struct LNode *next;
}LNode,*LinkList;
Status CreateLink_L(LinkList &L,int n)
{
LinkList p,s;
int i;
ElemType e;
L=new LNode;
L->next=NULL;
p=L;
for(i=0;i<n;i++)
{
scanf("%d",&e);
s=new LNode;
s->data=e;
s->next=NULL;
p->next=s;
p=s;
}
return OK;
}
Status CreateEmptyLink_L(LinkList &L,int n)
{
LinkList p,s;
int i;
L=new LNode;
L->next=NULL;
p=L;
for(i=0;i<n;i++)
{
s=new LNode;
s->data=0;
s->next=NULL;
p->next=s;
p=s;
}
return OK;
}
Status ListInsert_L(LinkList &L,int i,ElemType e)
{
LinkList p,s;
int j=1;
p=L;
while(p&&j<i)
{
p=p->next;
j++;
}
if(!p||j>i) return ERROR;
s=new LNode;
s->data=e;
s->next=p->next;
p->next=s;
return OK;
}
Status ListDelete_L(LinkList &L,int i,ElemType &e)
{
LinkList p,s;
int j=1;
p=L;
while(p->next&&j<=i)
{
s=p;
p=p->next;
j++;
}
if(!(p->next)||j>i) return ERROR;
e=p->data;
s->next=p->next;
delete p;
return OK;
}
Status LoadLink_L(LinkList &L)
{
LinkList p=L->next;
if(p==NULL) printf("The List is empty!");
else{
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}
printf("\n");
return OK;
}
Status MergeList_L(LinkList &LA, LinkList &LB,LinkList &LC)
{
LinkList pa,pb,pc;
pa=LA->next;
pb=LB->next;
LC=LA;
pc=LC;
while(pa&&pb)
{
if(pa->data<=pb->data)
{
pc->next=pa;
pc=pa;
pa=pa->next;
}
else
{
pc->next=pb;
pc=pb;
pb=pb->next;
}
}
pc->next=pa?pa:pb;
delete LB;
}
int main()
{
LinkList A,B,C;
int a,b;
scanf("%d",&a);
CreateLink_L(A,a);
printf("List A:");
LoadLink_L(A);
scanf("%d",&b);
CreateLink_L(B,b);
printf("List B:");
LoadLink_L(B);
CreateEmptyLink_L(C,a+b);
MergeList_L(A,B,C);
printf("List C:");
LoadLink_L(C);
}
19080 反转链表
时间限制:1000MS 代码长度限制:10KB
提交次数:0 通过次数:0
题型: 填空题 语言: 不限定
Description
一道经典的题目 给定一个单链表的头结点L,长度为n,反转该链表后,返回新链表的表头。 要求:空间复杂度 O(1) ,时间复杂度 O(n)。 如当输入链表{1,2,3}时, 经反转后,原链表变为{3,2,1},所以对应的输出为{3,2,1}。
#include <iostream>//C++
using namespace std;
struct LNode
{
int data;
LNode * next;
};
void createList(LNode * &L,int n)
{
/**< 尾插法创建单链表 */
LNode *r, *p;
r=L=new LNode;/**< 创建头结点 */
L->next=NULL;
for(int i=1; i<=n; i++)
{
p=new LNode;
cin>>p->data;
p->next=NULL;
r->next=p;
r=p;
}
}
void trv(LNode * L)
{
/**< 一个简单的链表遍历函数,供编程过程中测试使用 */
L=L->next;
while(L)
{
cout<<L->data<<' ';
L=L->next;
}
}
void reverseList(LNode * &L)
{
_______________________
}
int main()
{
int n;
LNode *L;
cin>>n;
createList(L,n);
reverseList(L);
trv(L);
return 0;
}
输入格式
第一行一个整数n,代表链表长度。 第二行n个整数。
输出格式
输出逆置后的单链表。
输入样例
5 1 2 3 4 5
输出样例
5 4 3 2 1
代码:
#include <iostream>//C++
using namespace std;
struct LNode
{
int data;
LNode * next;
};
void createList(LNode * &L,int n)
{
/**< 尾插法创建单链表 */
LNode *r, *p;
r=L=new LNode;/**< 创建头结点 */
L->next=NULL;
for(int i=1; i<=n; i++)
{
p=new LNode;
cin>>p->data;
p->next=NULL;
r->next=p;
r=p;
}
}
void trv(LNode * L)
{
/**< 一个简单的链表遍历函数,供编程过程中测试使用 */
L=L->next;
while(L)
{
cout<<L->data<<' ';
L=L->next;
}
}
void reverseList(LNode * &L)
{
LNode *pre,*cur,*nex;
pre=NULL;
cur=L->next;
nex=NULL;
while(cur)
{
pre=cur;
cur=cur->next;
pre->next=nex;//最重要的
nex=pre;
}
L->next=pre;
}
int main()
{
int n;
LNode *L;
cin>>n;
createList(L,n);
reverseList(L);
trv(L);
return 0;
}