예제 #1
0
int main(int argc, char* argv[]) {
  ApplyCustomNewHandler();

  Chain<int> c;
  for (int i = 0; i < 20; i++) {
    c.Insert(i, (i + 1) * (i + 1));
  }

  for (int i = 9; i >= 0; i--) {
    int x;
    c.Delete(i, x);
  }

  c.Output(std::cout);

  std::cout << std::endl << std::endl;

  Chain<int> cp = c;
  cp.Reverse();
  for (Chain<int>::Iterator it = cp.Begin(); it != cp.End(); ) {
    std::cout << *it++ << " ";
  }

//--------------------------------------------------------------------------
  Chain<int> cr1 = cp;
  Chain<int> cr2;
  CHighResTimeCounter tc;

  tc.Begin();
  cr1.Reverse();
  tc.End();
  std::cout << "\nTime costed: " << tc.GetElapsedTimeInMS() << std::endl;

  tc.Begin();
  ReverseChain(cr1, cr2);
  tc.End();
  std::cout << "\nTime costed: " << tc.GetElapsedTimeInMS() << std::endl;

//--------------------------------------------------------------------------
  Chain<int> ca = c;
  ca.Insert(0, 7);
  ca.Insert(4, 5);
  ca.Insert(7, 11);
  ca.BubbleSort();
  cout << ca << endl;

  ca.Clear();
  ca.Insert(0, 49);
  ca.Insert(0, 18);
  ca.Insert(0, 7);
  ca.Insert(0, 19);
  ca.Insert(0, 8);
  ca.Insert(0, 37);
  ca.SelectionSort();
  cout << ca << endl;
  ca.SelectionSort(false);
  cout << ca << endl;

  return 0;
}
예제 #2
0
void main(void)
{
   try {
      Chain<int> L;
      cout << "Length = " << L.Length() << endl;
      cout << "IsEmpty = " << L.IsEmpty() << endl;
      L.Insert(0,2).Insert(1,6);
      cout << "List is " << L << endl;
      cout << "IsEmpty = " << L.IsEmpty() << endl;
      int z;
      L.Find(1,z);
      cout << "First element is " << z << endl;
      cout << "Length = " << L.Length() << endl;
      L.Delete(1,z);
      cout << "Deleted element is " << z << endl;
      cout << "List is " << L << endl;
      }
   catch (...) {
      cerr << "An exception has occurred" << endl;
      }
}