标签:source tail user http group content line rip submit
4 1 1 1 2 0 3 100 4
3 1 2 4
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef struct node 4 { 5 int data; 6 struct node*next; 7 }tree; 8 int main() 9 { 10 int n,m,x; 11 struct node*head,*tail,*p,*q; 12 while(~scanf("%d",&n))//注意多组输入 13 { 14 head=new tree; 15 head->next=NULL;//顺序建立链表 16 tail=head; 17 while(n>0) 18 { 19 q=head;//一开始将q游动指针放在头指针位置处来进行初始化 20 scanf("%d %d",&m,&x); 21 while(m--&&q->next)//这个while循环的作用是确定题目中给的目标位置 22 { 23 q=q->next; 24 } 25 p=new tree;//确定了之后开始用P游动指针来建立链表 26 p->data=x; 27 p->next=NULL; 28 p->next=q->next; 29 q->next=p; 30 n--; 31 } 32 p=head->next;//最后进行链表的输出 33 while(p) 34 { 35 if(p->next==NULL) 36 { 37 printf("%d\n",p->data); 38 } 39 else 40 { 41 printf("%d ",p->data); 42 } 43 p=p->next; 44 } 45 } 46 47 return 0; 48 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 struct node 4 { 5 int data; 6 struct node *next; 7 }; 8 int main() 9 { 10 int n,m,x; 11 struct node *head,*p,*q; 12 while(~scanf("%d",&n)) 13 { 14 head=(struct node *)malloc(sizeof(struct node)); 15 head->next=NULL; 16 while(n--) 17 { 18 q=head; 19 scanf("%d %d",&m,&x); 20 while(m--&&q->next) 21 q=q->next; 22 p=(struct node *)malloc(sizeof(struct node)); 23 p->data=x; 24 p->next=NULL; 25 p->next=q->next; 26 q->next=p; 27 } 28 q=head->next; 29 while(q) 30 { 31 if(q->next==NULL) printf("%d\n",q->data); 32 else printf("%d ",q->data); 33 q=q->next; 34 } 35 } 36 return 0; 37 }
标签:source tail user http group content line rip submit
原文地址:https://www.cnblogs.com/xiaolitongxueyaoshangjin/p/12063605.html