There are some small balls, numbered from left to right 1 2 3 ... n
After executing a 1 4, the ball 1 is moved to the left of 4
After performing B 3 5, the ball 3 is moved to the right of 5
Sample input:
6 2
A 1 4
B 3 5
Sample output:
214536
1#include <stdio.h>2 Const intn=50000;3 structNode4 {5 intorder;6Node *left,*Right ;7 }node[n];8 9 voidCreateNode (intN)Ten { One inti; A for(i =1; I <= n;i++) - { -Node[i].order =i; theNode[i].right = &node[i+1]; -node[i+1].left= &Node[i]; - } -node[0].left =NULL; +node[0].right = &node[1]; -node[1].left = &node[0]; +Node[i].right =NULL; A } at voidAintXinty) - { -Node *p = &node[x],*q = &Node[y]; -P->right->left=p->Left ; -P->left->right=p->Right ; -p->right=Q; inP->left=q->Left ; -q->left->right=p; toq->left=p; + } - the voidBintXinty) * { $Node *p = &node[x],*q = &Node[y];Panax NotoginsengP->right->left = p->Left ; -P->left->right = p->Right ; theP->left =Q; +P->right = q->Right ; AQ->right->left =p; theQ->right =p; + } - intMain () $ { $ intn,m; - Charcmd; - intx, y; thescanf"%d%d",&n,&m); - CreateNode (n);Wuyi while(m--) the { -scanf"%*c%c%d%d",&cmd,&x,&y); Wu if(cmd = ='A') - A (x, y); About if(cmd = ='B') $ B (x, y); - } -Node *l = &node[0]; -L = l->Right ; A while(l->Right ) + { theprintf"%d",l->order); -L = l->Right ; $ } the return 0; the}
Thank you for helping me with this blog : http://blog.csdn.net/taotaotaotao910429/article/details/7831479
Mobile Ball Chain List implementation