数据结构专题——链表处理 A1032.Sharing (静态链表)
#include <bits/stdc++.h> #include<math.h> #include <string> using namespace std; const int maxn = 100010; struct Node{//定义静态链表 char data; int next; bool flag; }node[maxn]; int main(){ for(int i =0;i<maxn;++i){ node[i].flag = false; } int s1,s2,n;//s1和s2分别代表两条链表的首地址 scanf("%d%d%d",&s1,&s2,&n); int address,next;//节点地址与后继节点地址 char data; for(int i=0;i<n;++i){ scanf("%d %c %d",&address,&data,&next); node[address].data = data; node[address].next = next; } int p; for(p = s1;p != -1;p = node[p].next){ node[p].flag = true;//枚举第一条链表的所有节点,令其出现次数为1 } for(p = s2;p != -1;p = node[p].next){ if(node[p].flag == true){ break; } } if(p != -1){ printf("%05d\n",p); }else{ printf("-1\n"); } system("pause"); return 0; }
相关推荐
koushr 2020-11-12
范范 2020-10-28
qiangde 2020-09-13
范范 2020-07-30
mingyunxiaohai 2020-07-19
zhaochen00 2020-10-13
Mars的自语 2020-09-27
steeven 2020-09-18
kka 2020-09-14
聚沙成塔积水成渊 2020-08-16
earthhouge 2020-08-15
aanndd 2020-08-12
bluetears 2020-07-28
horizonheart 2020-07-19
liushall 2020-07-18
bluetears 2020-07-05
fengshantao 2020-07-02
liuweixiao0 2020-06-27