【笔记】链表

小兔子乖乖,把门开开。不开不开就不开,jc没回来,嘿嘿嘿。
怀疑当时怎么学的邻接表。感觉链表还是不会用。
果然辣鸡,需要补;

先放小白(紫)代码:

#include <cstdio>
#include <queue>
#include <iostream>
#include <cstring>
using namespace std;

const int MAXN = 100010;
char s[MAXN];
int next[MAXN];
int last, cur;

int main()
{
    while(scanf("%s",s+1) == 1)
    {
        int n = strlen(s+1);
        last = cur = 0;
        next[0] = 0;
        for(int i = 1; i <= n; i ++)
        {
            char c = s[i];
            if(c == '[') // 如果出现 '[' , 那么后面的字符我们需要先输出; 
                cur = 0; // 使 next[0] = '[' ,后面的第一个字符的下标;
            else if(c == ']') // 出 ] 时继续进括号时的 last 下标; 
                cur = last; 
            else{
                next[i] = next[cur]; // next[i] = 光标后面的字符的下标; 
                next[cur] = i;// 赋值光标的后面的的下标; 
                if(cur == last) // 如果当前光标在[]里面,那么这个if不会执行,last保持原状; 
                    last = i;
                cur = i;// 不管是否在那里进行字符处理,都要进行光标的移动。 
            }
        }
        for(int i = next[0]; i != 0; i = next[i])
            printf("%c", s[i]);
        printf("\n");
    }
    return 0;
}

先来一波破损的键盘的简化过程:

A _ [ B e ] _
1 2 3 4 5 6 7

// A
cur = 0;
last = 0;
next[0] = 0;
next[1] = next[0];
next[0] = 1;
last = 1;
cur = 1;

// _
next[2] = next[1];
next[1] = 2;
last = 2;
cur = 2; 

// [
cur = 0;
last = 2;
cur = 0;

// B
next[4] = next[0];
next[0] = 4;
last = 2;
cur = 4;

// e
next[5] = next[4];
next[4] = 5;
last = 2;
cur = 5;

// ]
cur = last = 2;

// _
next[7] = next[2];
next[2] = 7;
last = 7;
cur = 7;


for(int i = next[0]; i != 0; i = next[i])
next[0] = 4; next[4] = 5; next[5] = 1; next[1] = 2; next[2] = 7; next[7] = 0;

再回首。
邻接表建图:

tot ++;
next[tot] = first[ff];
first[ff] = tot;

这个就没有什么好说的了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值