码迷,mamicode.com
首页 > 其他好文 > 详细

数据结构专题——链表处理 A1032.Sharing (静态链表)

时间:2020-01-18 21:26:50      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:str   后继节点   处理   ring   div   lag   info   struct   class   

技术图片

 

 

#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;
} 

数据结构专题——链表处理 A1032.Sharing (静态链表)

标签:str   后继节点   处理   ring   div   lag   info   struct   class   

原文地址:https://www.cnblogs.com/JasonPeng1/p/12210062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!