home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / prog / graphics / rb_tree.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  1.5 KB  |  74 lines

  1. #include <LEDA/rb_tree.h>
  2. #include <LEDA/window.h>
  3.  
  4. window W(SCREEN_WIDTH,SCREEN_HEIGHT);
  5.  
  6. color node_color1 = black;
  7. color node_color2 = red;
  8. color edge_color  = blue;
  9.  
  10. void draw_black_node(double x, double y, void* i)
  11. { W.draw_filled_node(x,y,node_color1);
  12.   W.draw_ctext(x,y,form("%d",i),white);
  13.  }
  14.  
  15. void draw_red_node(double x, double y, void* i)
  16. { W.draw_filled_node(x,y,node_color2);
  17.   W.draw_node(x,y,black);
  18.   W.draw_ctext(x,y,form("%d",i),black);
  19.  }
  20.  
  21. void draw_edge(double x0, double y0, double x1, double y1)
  22. { W.draw_edge(x0,y0,x1,y1,edge_color); }
  23.  
  24. main()
  25. {
  26.   rb_tree T;
  27.   panel P("RED BLACK TREES");;
  28.  
  29.   int node_width = 12;
  30.   int edge_width = 1;
  31.   int n = 100;
  32.   int mode = 0;
  33.  
  34.   if (W.mono()) node_color2 = white;
  35.     
  36.   P.choice_item("INPUT",mode,"random", "1..N");
  37.  
  38.   P.int_item("INSERTS",n);
  39.   P.int_item("node width",node_width,1,20);
  40.   P.int_item("edge width",edge_width,1,8,1);
  41.  
  42.   P.color_item("node color1",node_color1);
  43.   P.color_item("node color2",node_color2);
  44.   P.color_item("edge color", edge_color);
  45.  
  46.   for(;;)
  47.   {
  48.     P.open();
  49.  
  50.     W.clear();
  51.     W.set_node_width(node_width);
  52.     W.set_line_width(edge_width);
  53.     W.set_text_mode(transparent);
  54.   
  55.     T.clear();
  56.   
  57.     init_random();
  58.   
  59.     if (mode==0)
  60.       while (n--) T.insert((void*)random(0,99),0);
  61.     else
  62.       for(int i=0;i<n;i++) T.insert((void*)i,0);
  63.   
  64.     double dy = (W.ymax()-W.ymin())/10;
  65.   
  66.     T.draw(draw_red_node,draw_black_node,draw_edge,
  67.            W.xmin(),W.xmax(),W.ymax()-dy,dy);
  68.   
  69.     W.read_mouse();
  70.   
  71.   }
  72.   
  73. }
  74.