pset.c
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:3k
开发平台:

MultiPlatform

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