AcWing 826. singly linked list

https://www.acwing.com/activity/content/problem/content/863/1/

#include <the iostream>
 the using  namespace STD;
 const  int N = 100010 ;
 // head point represents the point at which the head node 
 // E [i] represents the value of node i
 // NE [i] denotes the next pointer node i number
 // IDX stores the current point which has used the 
int head, E [N], NE [N], IDX;
 // initialize 
void the init () { 
    head = - . 1 ; 
    IDX = 0 ; // start bit 0 
}
 // the head node x into the 
void add_to_head ( int x) { 
    E [IDX] = x;   // record x
    NE [IDX] = head; // this point becomes the original point of the head points 
    head IDX = ++; // head points IDX 
}
 // The subscript x is inserted behind the point k 
void the Add ( int k , int X) { 
    E [IDX] = X; 
    NE [IDX] = NE [k]; // point number k of the original points of 
    NE [k] = IDX ++; // k point IDX 
}
 // Set index a point behind the point k deleted 
void Remove ( int k) { 
    NE [k] = NE [NE [k]]; 
} 
int main () {
     int m; 
    CIN >> m;
    the init (); // initialize 
    the while (m - ) {
         int K, X;
         char OP; 
        CIN >> OP;
         IF (OP == ' H ' ) { 
            CIN >> X; 
            add_to_head (X); 
        } the else  IF (OP == ' D ' {) 
            CIN >> ; K
             IF head NE = [head] (K!);   // Laid judged equal to 0 
            the else Remove (K - . 1 ); 
        }the else { 
            CIN >> >> K X; 
            the Add (K - . 1 , X);   // One is the second point of insertion, so to be a Save 
        } 
    } 
    for ( int I = head; I = -! . 1 ; NE = I [I]) COUT << E [I] << '  ' ; 
    COUT << endl;
     return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/QingyuYYYYY/p/11790096.html