home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / prog / plane / pset.c < prev   
Encoding:
C/C++ Source or Header  |  1991-11-15  |  2.6 KB  |  115 lines

  1. #include <LEDA/point_set.h>
  2.  
  3. declare(point_set,string)
  4.  
  5.  
  6.  
  7. main()
  8. {
  9.  
  10.   point_set(string) S;
  11.  
  12.   list(ps_item) L;
  13.   ps_item       it=nil;
  14.   point         p; 
  15.   char          ch;
  16.  
  17.  
  18.  
  19.   while (ch != 'q')
  20.   { 
  21.     cout << "(r/s/f/n/i/d/D/l/q): ";
  22.     cin  >> ch;
  23.  
  24.     float T  = used_time();
  25.      
  26.     switch(ch) {
  27.  
  28.     case 'i':  cout << "insert point: ";
  29.                cin >> p;
  30.                S.insert(p,string("x = %f",p.xcoord()));
  31.                break;
  32.  
  33.  
  34.      case 'n': { cout << "nearest neighbor: ";
  35.              cin >> p;
  36.                  it = S.nearest_neighbor(p);
  37.                  if (it!=nil) cout << S.key(it);
  38.                  else cout << "Empty point set.\n";    
  39.                  newline;
  40.                  break;
  41.                }
  42.  
  43.  
  44.     case 'r' : { init_random();
  45.                  int n = read_int("#random points = ");
  46.                  while (n--)
  47.                  { double x = random(1,1000)/100.0;
  48.                    double y = random(1,1000)/100.0;
  49.                    S.insert(point(x,y),string("x = %f",x));
  50.                   }
  51.                  cout << form("time: %6.2f\n",used_time(T));
  52.                  break;
  53.                 }
  54.  
  55.     case 's': { double a=read_real("x0=");
  56.                 double b=read_real("x1=");
  57.                 double c=read_real("y0=");
  58.                 double d=read_real("y1=");
  59.   
  60.                 L = S.range_search(a,b,c,d);
  61.   
  62.                 forall(it,L) cout << S.key(it) << " " << S.inf(it) << "\n";
  63.                 newline;
  64.               
  65.                 cout << form("time: %6.2f\n",used_time(T));
  66.                 break;
  67.               }
  68.  
  69.  
  70.     case 'd': { cout << "delete point: ";
  71.             cin >> p;
  72.                 S.del(p);
  73.                 break;
  74.                }
  75.  
  76.     case 'D': { double a=read_real("x0=");
  77.                 double b=read_real("x1=");
  78.                 double c=read_real("y0=");
  79.                 double d=read_real("y1=");
  80.   
  81.                 L = S.range_search(a,b,c,d);
  82.   
  83.                 forall(it,L) 
  84.                 { point p = S.key(it);
  85.                   cout << "delete: " << p <<"\n";
  86.                   S.del(p);
  87.                  }
  88.                 newline;
  89.               
  90.                 cout << form("time: %6.2f\n",used_time(T));
  91.                 break;
  92.               }
  93.  
  94.  
  95.     case 'f': { cout << "find point: ";
  96.             cin >> p;
  97.                 if (S.lookup(p) != nil) cout << "yes";
  98.                 else cout << "no";
  99.                 newline;
  100.                 break;
  101.                }
  102.  
  103.  
  104.     case 'l': L = S.all_items();
  105.               forall(it,L) 
  106.                 cout << S.key(it) << " " << S.inf(it) << "\n";
  107.               newline;
  108.               break;
  109.  
  110.  
  111.     } //switch
  112.  
  113.   } //for
  114. }
  115.