[ACW] 826. Single chain

Chain of title

tips:

  1. The single chain analog array, fast

  2. Some questions to consider boundary conditions of the people have been removed

  3. understanding of the meaning of problems

  4. The index is used to distinguish an index, a pointer, the logical and physical

#include<iostream>

using namespace std;

const int N=10010;

int head,e[N],ne[N],idx;

void init(){
    head=-1;
    idx=0;
}

void add_to_head(int x){
    e[idx]=x;
    ne[idx]=head;
    head=idx;
    idx++;
}

void add(int k,int x){
    e[idx]=x;
    ne[idx]=ne[k];
    ne[k]=idx;
    idx++;
}

void rremove(int k){
    ne[k]=ne[ne[k]];
}
int main(){
    int m;
    cin>> m;
    init();
    while(m--){
        int k,x;
        char op;
        inc>>op;

        if(op == 'H'){
            cin>>x;
            add_to_head();
        }
        else if(op == 'D'){
            cin>>k;
            if(!k) head=ne[head];
            rremove(k-1);
        }
        else{
            cin>>k>>x;
            add(k-1,x);
        }
    }

    for(int i=head; i!=-1; i=ne[i]) cout<<e[i]<<' ';
    cout<<endl;
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/SUMaywlx/p/11440862.html