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

Method add

src/class153/FollowUp1.java:108–133  ·  view source on GitHub ↗
(int num)

Source from the content-addressed store, hash-verified

106 }
107
108 public static void add(int num) {
109 key[++cnt] = num;
110 size[cnt] = 1;
111 if (head == 0) {
112 head = cnt;
113 } else {
114 int f = 0, i = head, son = 0;
115 while (i != 0) {
116 f = i;
117 if (key[i] <= num) {
118 son = 1;
119 i = right[i];
120 } else {
121 son = 0;
122 i = left[i];
123 }
124 }
125 if (son == 1) {
126 right[f] = cnt;
127 } else {
128 left[f] = cnt;
129 }
130 father[cnt] = f;
131 splay(cnt, 0);
132 }
133 }
134
135 public static int rank(int num) {
136 int i = head, last = head;

Callers 6

mainMethod · 0.95
verifyAddMethod · 0.45
verifyMergeMethod · 0.45
verifyPopMethod · 0.45
checkMethod · 0.45
mainMethod · 0.45

Calls 1

splayMethod · 0.95

Tested by

no test coverage detected