Skip to content

Commit f72fde5

Browse files
committed
Add Sedgewick min NULL fail as regression test
1 parent ed4ce85 commit f72fde5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stddef.h>
2+
#include <assert.h>
3+
4+
struct node {
5+
struct node *left;
6+
struct node *right;
7+
int key;
8+
};
9+
10+
// https://old.reddit.com/r/programminghorror/comments/jgrpcu/on_sedgewicks_original_presentation_for_llrb_trees/
11+
struct node* min(struct node *root) {
12+
struct node *x = root;
13+
while (x != NULL)
14+
x = x->left;
15+
if (x == NULL) // WARN (dead branch)
16+
return NULL;
17+
else
18+
return x;
19+
}
20+
21+
int main() {
22+
struct node *root;
23+
struct node *m = min(root);
24+
assert(m == NULL);
25+
return 0;
26+
}

0 commit comments

Comments
 (0)