国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

師--鏈表的結點插入

2019-11-06 06:12:02
字體:
來源:轉載
供稿:網友

師--鏈表的結點插入

Time Limit: 1000MS Memory Limit: 65536KBSubmit Statistic

PRoblem Description

給出一個只有頭指針的鏈表和 n 次操作,每次操作為在鏈表的第 m 個元素后面插入一個新元素x。若m 大于鏈表的元素總數則將x放在鏈表的最后。

Input

多組輸入。每組數據首先輸入一個整數n(n∈[1,100]),代表有n次操作。接下來的n行,每行有兩個整數Mi(Mi∈[0,10000]),Xi。

Output

對于每組數據。從前到后輸出鏈表的所有元素,兩個元素之間用空格隔開。

Example Input

41 11 20 3100 4

Example Output

3 1 2 4

Hint

 

Author

01#include<bits/stdc++.h>
02using namespace std;
03 
04struct node
05{
06    int data;
07    node *next;
08};
09int len;
10node *head;
11 
12void Insert(int m,int n)
13{
14    node *p,*tail;
15    tail=head;
16    for(int i=0;i<m&&i<len;i++)//從頭結點處一直到序列m點,或者直到指向空
17        tail=tail->next;
18    p=new node;
19    p->data=n;
20    p->next=tail->next;
21    tail->next=p;
22    len++;
23}
24 
25void print()
26{
27    node *p;
28    p=head->next;
29    while(p)
30    {
31        if(p->next)
32            printf("%d ",p->data);
33        else
34            printf("%d/n",p->data);
35        p=p->next;
36    }
37}
38 
39int main()
40{
41    int t,m,n;
42    while(~scanf("%d",&t))
43    {
44        head=new node;
45        len=0;
46        for(int i=0;i<t;i++)
47        {
48            scanf("%d%d",&m,&n);
49            Insert(m,n);
50        }
51        print();
52    }
53    return 0;
54}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丹凤县| 临高县| 鸡西市| 永兴县| 大连市| 安多县| 库伦旗| 杭锦后旗| 永吉县| 卓资县| 错那县| 彭州市| 上思县| 旬邑县| 昭通市| 沁阳市| 泰宁县| 宝坻区| 元谋县| 永丰县| 肃南| 仁寿县| 宜兴市| 金川县| 丹寨县| 阳城县| 柘城县| 沙雅县| 长垣县| 延安市| 甘泉县| 壤塘县| 潜江市| 保靖县| 汉中市| 新建县| 丰城市| 蓬安县| 库车县| 曲阳县| 永宁县|