数据结构实验之链表一:顺序建立链表(SDUT 2116)
生活随笔
收集整理的這篇文章主要介紹了
数据结构实验之链表一:顺序建立链表(SDUT 2116)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Problem Description
輸入N個整數,按照輸入的順序建立單鏈表存儲,并遍歷所建立的單鏈表,輸出這些數據。
Input
第一行輸入整數的個數N;
第二行依次輸入每個整數。
Output
輸出這組整數。
Sample Input
8
12 56 4 6 55 15 33 62
Sample Output
12 56 4 6 55 15 33 62
Hint
不得使用數組!
?
#include <bits/stdc++.h>using namespace std;struct node {int data;struct node *next; }; int main() {int n;struct node *head, *tail, *p;head = new node;head -> next = NULL;tail = head;scanf("%d",&n);for(int i = 0; i < n; i ++){p = new node;p -> next = NULL;scanf("%d", &p -> data);tail -> next = p;tail = p;}for(p = head -> next ; p != NULL; p = p -> next){if(p == head -> next)printf("%d",p->data);elseprintf(" %d",p->data);}printf("\n");return 0; }?
轉載于:https://www.cnblogs.com/lcchy/p/10139510.html
總結
以上是生活随笔為你收集整理的数据结构实验之链表一:顺序建立链表(SDUT 2116)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Appium录制脚本520-2
- 下一篇: luogu P3293 [SCOI201