home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__lib / tvec.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-23  |  2.0 KB  |  91 lines

  1. /*
  2.  test/demo of Vecs, AVecs
  3. */
  4.  
  5. #include <stream.h>
  6. #include "int.Vec.h"
  7. #include "int.AVec.h"
  8.  
  9. int int_compare(int a, int b)
  10. {
  11.   return a - b;
  12. }
  13.  
  14. int plus(int a, int b)
  15. {
  16.   return a + b;
  17. }
  18.  
  19. int inc(int a)
  20. {
  21.   return a + 1;
  22. }
  23.  
  24. void printint(int a)
  25. {
  26.   cout << a << " ";
  27. }
  28.  
  29. void print(intVec& a)
  30. {
  31.   a.apply(printint);
  32.   cout << "\n";
  33. }
  34.     
  35. main()
  36. {
  37.   intVec a(20);
  38.   for (int i = 0; i < a.capacity(); ++i) a[i] = rand() % 100;
  39.   cout << "a: "; print(a);
  40.   a.sort(int_compare);
  41.   cout << "a.sort():"; print(a);
  42.   intVec b = map(inc, a);
  43.   cout << "b = map(inc, a): "; print(b);
  44.   intVec c = merge(a, b, int_compare);
  45.   cout << "c = merge(a, b): "; print(c);
  46.   intVec d = concat(a, b);
  47.   cout << "d = concat(a, b): "; print(d);
  48.   d.resize(10);
  49.   cout << "d.resize(10): "; print(d);
  50.   d.reverse();
  51.   cout << "d.reverse(): "; print(d);
  52.   d.fill(0, 4, 4);
  53.   cout << "d.fill(0, 4, 4): "; print(d);
  54.   cout << "d.reduce(plus, 0) = " <<   d.reduce(plus, 0) << "\n";
  55.   intVec e = d.at(2, 5);
  56.   cout << "e = d.at(2, 5): "; print(e);
  57.  
  58.   intAVec x(20);
  59.   for (i = 0; i < x.capacity(); ++i) x[i] = i;
  60.   cout << "x: "; print(x);
  61.   intAVec y(20);
  62.   for (i = 0; i < y.capacity(); ++i) y[i] = rand() % 100 + 1;
  63.   cout << "y: "; print(y);
  64.  
  65.   cout << "x + y: "; print(x + y);
  66.   cout << "x - y: "; print(x - y);
  67.   cout << "product(x, y): "; print(product(x,y));
  68.   cout << "quotient(x, y): "; print(quotient(x,y));
  69.   cout << "x * y: " << (x * y) << "\n";
  70.  
  71.   cout << "x + 2: "; print(x + 2);
  72.   cout << "x - 2: "; print(x - 2);
  73.   cout << "x * 2: "; print(x * 2);
  74.   cout << "x / 2: "; print(x / 2);
  75.  
  76.   intAVec z(20, 1);
  77.   cout << "z(20, 1): "; print(z);
  78.   cout << "z = -z: "; print(z = -z);
  79.   cout << "z += x: "; print(z += x);
  80.   cout << "z -= x: "; print(z -= x);
  81.  
  82.   cout << "x.sum(): " << x.sum() << "\n";
  83.   cout << "x.sumsq(): " << x.sumsq() << "\n";
  84.   cout << "x.min(): " << x.min() << "\n";
  85.   cout << "x.max(): " << x.max() << "\n";
  86.   cout << "x.min_index(): " << x.min_index() << "\n";
  87.   cout << "x.max_index(): " << x.max_index() << "\n";
  88.  
  89.   cout << "\nEnd of test\n";
  90. }
  91.