SDUT_2116 数据结构实验之链表一:顺序建立链表
生活随笔
收集整理的這篇文章主要介紹了
SDUT_2116 数据结构实验之链表一:顺序建立链表
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
點擊打開鏈接
數據結構實驗之鏈表一:順序建立鏈表
Time Limit:?1000MS?Memory Limit:?65536KB Submit?Statistic?DiscussProblem Description
輸入N個整數,按照輸入的順序建立單鏈表存儲,并遍歷所建立的單鏈表,輸出這些數據。Input
第一行輸入整數的個數N;第二行依次輸入每個整數。
Output
輸出這組整數。Example Input
8 12 56 4 6 55 15 33 62Example Output
12 56 4 6 55 15 33 62Hint
#include <iostream> using namespace std; struct node {int num;node *next; }; int main() {int n;node *head,*tail,*p;head=new node;head->next=NULL;tail=head;cin>>n;for(int i=0;i<n;i++){p=new node;cin>>p->num;p->next=NULL;tail->next=p;tail=p;}node *q;q=new node;q=head->next;while(q!=NULL){if(q->next!=NULL)cout<<q->num<<' ';elsecout<<q->num<<endl;q=q->next;}return 0; }/*************************************************** User name: YT1658506207邵雪源 Result: Accepted Take time: 0ms Take Memory: 208KB Submit time: 2017-08-02 12:37:40 ****************************************************/《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的SDUT_2116 数据结构实验之链表一:顺序建立链表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第2周项目1c++语言中函数参数传递的三
- 下一篇: SDUT _2117 数据结构实验之链表