网站域名备案与解析,优秀网页设计,河南省住房和城乡建设厅官网证书查询,计算机网站建设与管理是什么意思题目1518#xff1a;反转链表 时间限制#xff1a;1 秒 内存限制#xff1a;128 兆 特殊判题#xff1a;否 提交#xff1a;2567 解决#xff1a;948 题目描述#xff1a;输入一个链表#xff0c;反转链表后#xff0c;输出链表的所有元素。(hint : 请务必使用链表) 输…题目1518反转链表 时间限制1 秒 内存限制128 兆 特殊判题否 提交2567 解决948 题目描述 输入一个链表反转链表后输出链表的所有元素。(hint : 请务必使用链表) 输入 输入可能包含多个测试样例输入以EOF结束。对于每个测试案例输入的第一行为一个整数n(0n1000)代表将要输入的链表的个数。输入的第二行包含n个整数t(0t1000000)代表链表元素。 输出 对应每个测试案例以此输出链表反转后的元素如没有元素则输出NULL。 样例输入 5
1 2 3 4 5
0 样例输出 5 4 3 2 1
NULL 1 #include cstdio2 #include cstring3 #include string4 #include queue5 #include stack6 #include iostream7 using namespace std;8 struct node{9 node *fro,*next;
10 int v;
11 };
12 int main(){
13 //freopen(D:\\INPUT.txt,r,stdin);
14 node *head,*tail;
15 int n;
16 while(scanf(%d,n)!EOF){
17 if(!n){
18 coutNULLendl;
19 }
20 else{
21 headnew node();
22 tailhead;
23 head-frohead-nextNULL;
24 scanf(%d,head-v);
25 int i;
26 node *p;
27 for(i1;in;i){//输入
28 pnew node();
29 p-frotail;
30 tail-nextp;
31 scanf(%d,p-v);
32 p-nextNULL;
33 tailp;
34 }
35 couttail-v;
36 ptail-fro;
37 delete tail;
38 p-nextNULL;
39 tailp;
40 while(tail!head){//转置链表
41 cout tail-v;
42 ptail-fro;
43 delete tail;
44 tailp;
45 }
46 cout tail-vendl;
47 delete head;
48 }
49 }
50 return 0;
51 } 转载于:https://www.cnblogs.com/Deribs4/p/4649467.html