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

  1. #include <LEDA/dictionary.h>
  2. #include <LEDA/window.h>
  3.  
  4.  
  5. window W(SCREEN_WIDTH,SCREEN_HEIGHT);
  6.  
  7. void draw_black_node(double x, double y, void* i)
  8. { W.draw_filled_node(x,y);
  9.   W.draw_ctext(x,y,form("%d",i),white);
  10.  }
  11.  
  12. void draw_red_node(double x, double y, void* i)
  13. { W.draw_text_node(x,y,form("%d",i),red); }
  14.  
  15. void draw_edge(double x0, double y0, double x1, double y1)
  16. { W.draw_edge(x0,y0,x1,y1,blue); }
  17.  
  18. declare2(dictionary,int,int)
  19.  
  20. main()
  21. {
  22.   dictionary(int,int) T;
  23.  
  24.   int n = W.read_int("n = ");
  25.  
  26.   init_random();
  27.  
  28.   if (W.confirm("random"))
  29.     while (n--) T.insert(random(0,100),0);
  30.   else
  31.     for(int i=0;i<n;i++) T.insert(i,0);
  32.  
  33.   double dy = (W.ymax()-W.ymin())/10;
  34.  
  35.   T.draw(draw_black_node, draw_red_node,draw_edge, 
  36.          W.xmin(),W.xmax(),W.ymax()-dy,dy);
  37.  
  38.   W.read_mouse();
  39.  
  40. }
  41.