rbtree
diff test/test.c @ 3:53afe96233f2
changed the tail-recursive find and find_min to loops
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Sun, 09 Oct 2011 08:30:54 +0300 |
parents | 7205a7d8d3d6 |
children |
line diff
1.1 --- a/test/test.c Sun Oct 09 07:55:51 2011 +0300 1.2 +++ b/test/test.c Sun Oct 09 08:30:54 2011 +0300 1.3 @@ -102,7 +102,7 @@ 1.4 glLoadIdentity(); 1.5 1.6 if(input_buffer[0]) { 1.7 - char *prompt = "select node to delete: "; 1.8 + char *prompt = "select node: "; 1.9 char *buf = alloca(strlen(prompt) + strlen(input_buffer)); 1.10 1.11 glPushMatrix(); 1.12 @@ -304,23 +304,12 @@ 1.13 { 1.14 static int wposx = -1, wposy; 1.15 static char *inp_next; 1.16 + static char op; 1.17 1.18 switch(key) { 1.19 case 27: 1.20 exit(0); 1.21 1.22 - case 'f': 1.23 - case 'F': 1.24 - if(wposx >= 0) { 1.25 - glutPositionWindow(wposx, wposy); 1.26 - wposx = -1; 1.27 - } else { 1.28 - wposx = glutGet(GLUT_WINDOW_X); 1.29 - wposy = glutGet(GLUT_WINDOW_Y); 1.30 - glutFullScreen(); 1.31 - } 1.32 - break; 1.33 - 1.34 case 'a': 1.35 rb_inserti(tree, num_nodes++, 0); 1.36 glutPostRedisplay(); 1.37 @@ -339,6 +328,8 @@ 1.38 break; 1.39 1.40 case 'd': 1.41 + case 'f': 1.42 + op = key; 1.43 inp_next = input_buffer; 1.44 *inp_next++ = ' '; 1.45 *inp_next = 0; 1.46 @@ -383,8 +374,12 @@ 1.47 } else if(!rb_findi(tree, x)) { 1.48 fprintf(stderr, "%d not found in the tree\n", x); 1.49 } else { 1.50 - printf("deleting: %d\n", x); 1.51 - rb_deletei(tree, x); 1.52 + if(op == 'd') { 1.53 + printf("deleting: %d\n", x); 1.54 + rb_deletei(tree, x); 1.55 + } else { 1.56 + printf("%d found!\n", x); 1.57 + } 1.58 } 1.59 input_buffer[0] = 0; 1.60 glutPostRedisplay();