| 193 | } |
| 194 | |
| 195 | sTree * splay_delete(key_type i, sTree * t) { |
| 196 | /* Deletes i from the sTree if it's there. */ |
| 197 | /* Return a pointer to the resulting sTree. */ |
| 198 | sTree * x; |
| 199 | if (t==NULL) return NULL; |
| 200 | long root_value = t->value; |
| 201 | t = splay(i,t); |
| 202 | if (key_cmp(i, t->key) == 0) { /* found it */ |
| 203 | if (t->left == NULL) { |
| 204 | x = t->right; |
| 205 | } else { |
| 206 | x = splay(i, t->left); // i is the largest element in left sub sTree, |
| 207 | // so the new splay sTree does not have right sub sTree |
| 208 | x->right = t->right; |
| 209 | } |
| 210 | free_node(t); |
| 211 | if (x != NULL) { |
| 212 | x->value = root_value-1; |
| 213 | } |
| 214 | return x; |
| 215 | } |
| 216 | return t; /* It wasn't there */ |
| 217 | } |
| 218 | |
| 219 | |
| 220 | //sTree *find_node(key_type e, sTree *t) { |
no test coverage detected