MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / rotate

Method rotate

src/class201/Code05_OTOCI1.java:65–91  ·  view source on GitHub ↗
(int x)

Source from the content-addressed store, hash-verified

63 }
64
65 public static void rotate(int x) {
66 int f = fa[x], g = fa[f];
67 if (lr(x) == 0) {
68 ls[f] = rs[x];
69 if (ls[f] != 0) {
70 fa[ls[f]] = f;
71 }
72 rs[x] = f;
73 } else {
74 rs[f] = ls[x];
75 if (rs[f] != 0) {
76 fa[rs[f]] = f;
77 }
78 ls[x] = f;
79 }
80 if (!isroot(f)) {
81 if (lr(f) == 0) {
82 ls[g] = x;
83 } else {
84 rs[g] = x;
85 }
86 }
87 fa[f] = x;
88 fa[x] = g;
89 up(f);
90 up(x);
91 }
92
93 public static void splay(int x) {
94 int siz = 0;

Callers 1

splayMethod · 0.95

Calls 3

lrMethod · 0.95
isrootMethod · 0.95
upMethod · 0.95

Tested by

no test coverage detected