日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

九度oj题目1518:反转链表

發布時間:2023/12/10 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 九度oj题目1518:反转链表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目1518:反轉鏈表

時間限制:1 秒

內存限制:128 兆

特殊判題:

提交:2567

解決:948

題目描述:

輸入一個鏈表,反轉鏈表后,輸出鏈表的所有元素。
(hint : 請務必使用鏈表)

?

輸入:

輸入可能包含多個測試樣例,輸入以EOF結束。
對于每個測試案例,輸入的第一行為一個整數n(0<=n<=1000):代表將要輸入的鏈表的個數。
輸入的第二行包含n個整數t(0<=t<=1000000):代表鏈表元素。

?

輸出:

對應每個測試案例,
以此輸出鏈表反轉后的元素,如沒有元素則輸出NULL。

?

樣例輸入:
5 1 2 3 4 5 0
樣例輸出:
5 4 3 2 1 NULL

?

1 #include <cstdio> 2 #include <cstring> 3 #include <string> 4 #include <queue> 5 #include <stack> 6 #include <iostream> 7 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 cout<<"NULL"<<endl; 19 } 20 else{ 21 head=new node(); 22 tail=head; 23 head->fro=head->next=NULL; 24 scanf("%d",&head->v); 25 int i; 26 node *p; 27 for(i=1;i<n;i++){//輸入 28 p=new node(); 29 p->fro=tail; 30 tail->next=p; 31 scanf("%d",&p->v); 32 p->next=NULL; 33 tail=p; 34 } 35 cout<<tail->v; 36 p=tail->fro; 37 delete tail; 38 p->next=NULL; 39 tail=p; 40 while(tail!=head){//轉置鏈表 41 cout<<" "<<tail->v; 42 p=tail->fro; 43 delete tail; 44 tail=p; 45 } 46 cout<<" "<<tail->v<<endl; 47 delete head; 48 } 49 } 50 return 0; 51 }

?

轉載于:https://www.cnblogs.com/Deribs4/p/4649467.html

總結

以上是生活随笔為你收集整理的九度oj题目1518:反转链表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。