The topics are as follows:
Originally wrote a chain list, but there is a problem in writing, but after 3 groups of data, and later in the classmate's hint, with the array to emulate the list, and then I use 2 yuan array to simulate the two-way list, because this problem color is not repeated, so the simulation is relatively simple, the code is as follows:
#include <stdio.h>typedefstructcolor{intPre; intNext;} Color;color c[100001];intM,n;intMain () {inti,j,cr,p0=0, N0,p,q; Chars[4]; scanf ("%d%d",&n,&m); for(i=0; i<n;i++) {scanf ("%d",&CR); N0=CR; C[p0].next=N0; C[n0].pre=P0; P0=N0; } C[p0].next=-1; while(m) {scanf ("%s", s); if(s[0]=='A') {scanf ("%d%d",&p,&Q); P0=C[p].pre; C[p0].next=Q; C[q].pre=P0; C[q].next=P; C[p].pre=Q; N++; } if(s[0]=='D') {scanf ("%d",&P); P0=C[p].pre; N0=C[p].next; C[p0].next=N0; C[n0].pre=P0; N--; } m--; } printf ("%d\n", N); I=0; while(c[i].next!=-1) {printf ("%d", C[i].next); I=C[i].next; } return 0;}
This code has been evaluated because the Find delete add Time is O (1), so it is much stronger than the linked list. (It can be a bit more complicated if the color allows repetition, but a hash-like approach should be much stronger than a simple list)
Blue Bridge cup algorithm improves shield God and bar necklace