for (int i = 1; i < n; i++)
for (int j = 1; j < k; j++) rear = rear.next;
if (i == 1){
head.next = rear.next;
p = rear.next;
}
else{
p.next = rear.next;
p = rear.next;
}
rear.next = p.next;
p.next = rear; rear.next = null;
a,b,c = head,head.next,head.next.next; //若a,b为null则直接返回
a.next = null;
while(c != null){
b.next = a;
a = b;
b = c;
c = c.next;
}
b.next = a;
header.next = b; //如果采用头指针
t = x.left.right
这种左右混淆的错误。front = (rear - length + 1 + m) % m = (rear + length - 1) % m
void CreateBT(String pres,ins,BinaryNode t){
if(pres.length() == 0) t = null;
else{
t = new BinaryNode(pres[0]);
inpos = 0;
while(ins.ch[inpos] != pres[0]) inpos++;
CreateBT(pres(1,inpos),ins(0,inpos-1),t.left);
CreateBT(pres(inpos+1,pres.length()-1),ins(inpos+1,,pres.length()-1),t.right);
}
}
void Inthread(Node p, Node pre){
if(p != null){
Inthread(p.left, pre);
if(p.left == null){
p.left = pre;
p.leftthread = 1;
}
if(pre != null && pre.right == null){
pre.right = p;
pre.rightthread = 1;
}
pre = p;
Inthread(p.right,pre);
}
}
leftsize = leftsubtree nodes + 1
。搜索树的删除操作:BinaryNode remove(x, Node t){ //t = root
if (t == null) return t;
if (x < t.element){t.left = remove(x,t.left);}
elif(x > t.element){t.right = remove(x,t.right);}
elif(t.left != null && t.right != null){
t.element = findMin(t.right);
t.right = remove(t.element,t.right);
}
else{t = t.left == null ? t.right : t.left;}
return t;
}
void insert(x){
int i = ++current_size;
while(i != 1 && a[i/2]<x){
a[i] = a[i/2];
i /= 2;
}
a[i] = x;
}
void perc(int i){ //下滤,删除操作直接将最后元素赋给根,然后下滤
for(temp = a[i]; 2*i+1 < current_size; i = child){ //i = child在一次循环最后进行
child = 2*i+1; //假设从0开始算
if (child != current_size-1; a[child]< a[child+1]) child++;
if (temp < a[child]) a[i] = a[child];
}
a[child] = temp;
}
int find(int e){
while(parent[e]) e = parent[e];
return e;
}
int find(int e){
if (parents[e] < 0){return e;}
else{return parents[e] = find(parents[e]);}
}
int union(int root1,int root2){s[root1] = root2;}
int union(int r1,int r2){//C版本,增加bool数组,parent[r]表示节点数目
if(parent[r1] < parent[r2]){
root[r1] = false; //r1不再是根节点
parent[r2] += parent[r1];
parent[r1] = r2;
}
else{...}
}
//可以令parent[root]为负数表示树的高度
void dfs(int v,visited){
print(v)
visited[v] = 1;
w = first_neighbor(v)
if (w != -1){
if (visited[w] != 1) dfs(w);
w = next_neighbor(v,w);
}
}
void bfs(int v){
visited[v] = 1;
q.enquene(v);
while(!q.isempty()){
v = q.dequene();
w = first_neighbor(v);
while(w != -1){
if (visited[w] != 1){
print(w)
visited[w] = 1;
q.enquene(w);
}
w = next_neighbor(v,w);
}
}
}
void kruscal(){
MinHeap H; DisjSet s;
for (int i = 0; i < num_vertices;i++){
e = H.deleteMin();
u = s.find(e.u);
v = s.find(e.v);
if (u != v){ans++; s.union(u,v);}
}
}
void prim(){
for (int i = 1; i < n; i++){
lowcost[i] = Edge[0][i];
nearvex[i] = 0;
}
for (int i = 1; i < n; i++)
int v = 0, min = MAXINT;
for (int j = 1; j < n; j++)
if (nearvex[j] != -1 && lowcost[j] < min){
v = j;
min = lowcost[j];
}
if (v){
span_tree.insert(v)
nearvex[v] = -1;
for (int j = 1; j < n; j++)
if (nearvex[j] != -1 && lowcost[j] > Edge[v][j]){
nearvex[j] = v;
lowcost[j] = Edge[v][j];
}
}
}
void dijkstra(int v, int n){
s[v] = 1;
for (int i = 0; i < n-1; i++){
min = MAXINT, u = v
for (int j = 0; j < n; j++)
if (!s[j] && dist[j] < min){u = j; min = dist[j];}
s[u] = 1;
for (int w = 0; w < n; w++)
if (!s[w] && dist[w] > dist[u] + Edge[u][w]){
dist[w] = dist[u] + Edge[u][w];
path[w] = u;
}
}
}
void bellman(int v){
for (int i= 0; i < n; i++)//这里就考虑了经过0个点的情况
dist[i] = Edge[v][i];
if (i != v && dist[i] < MAXINT) path[i] = v;
else path[i] = -1;
for(int k = 2; k < n; k++)
for(int u = 0; u < n; u++)
if (u != v){
for (int i = 0; i < n; i++)
if (Edge[i][u] < MAXINT && dist[u] > dist[i]+ Edge[i][u]){
dist[u] = dist[i]+ Edge[i][u];
path[u] = i;
}
}
}
void floyed(){
init operation;//初始化a,把存在的边存进去,相关信息也存到path里
for(int k = 0; k < n; k++)
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if (a[i][k] + a[k][j] < a[i][j]){
a[i][j] = a[i][k] + a[k][j];
path[i][j] = path[k][j];
}
}
while(r[i] != i){t = r[i]; swap(a[t],a[i]); swap(r[t],r[i])}
void quicksort(a,left,right){
pivot = median3(a,left,right);
for (;;){
while(a[++i] < pivot)
while(a[--j] > pivot)
if (i < j) swap(a,i,j)
else break;
}
swap(a,i,right-1);
quicksort(a,0,i-1);
quicksort(a,i+1,right);
}