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
int _tmain(int argc, _TCHAR* argv[])
{
	Chain<int> chain;
	// test size
	cout << "Initial size of chain = "
		<< chain.Length() << endl;
	
	// test empty
	if (chain.IsEmpty()) cout << "chain is empty" << endl;
	else cout << "chain is not empty" << endl;

	// test insert
	chain.Insert(0, 2);
	chain.Insert(1, 6);
	chain.Insert(0, 1);
	chain.Insert(2, 4);
	chain.Insert(3, 5);
	chain.Insert(2, 3);

	cout << "Inserted 6 integers, list chain should be 1 2 3 4 5 6" << endl;
	cout << "Size of chain = " << chain.Length() << endl;
	if (chain.IsEmpty()) cout << "chain is empty" << endl;
	else cout << "chain is not empty" << endl;
	chain.Output();

	int x  = -1,y = -1,z = -1;
	// test find and search
	bool exist = chain.Find(5,x);
	int index = chain.Search(6);

	// test delete
	chain.Delelte(0,x);
	chain.Delelte(3,y);
	chain.Delelte(7,z);
	cout << "Size of chain = " << chain.Length() << endl;
	if (chain.IsEmpty()) cout << "chain is empty" << endl;
	else cout << "chain is not empty" << endl;
	chain.Output();

	return 0;
}
示例#3
0
int main(int argc, const char *argv[])
{
    Chain<int> X;
    int numbers[] = {
        216, 521, 425, 116, 91, 515, 124, 34, 96, 24};

    for (int i = 0; i < 10; i++)
        X.Insert(0, numbers[i]);
    std::cout<<"X is "<<X<<std::endl;
    X.BinSort(9, GeWei);
    std::cout<<"after BinSort, X is "<<X<<std::endl;
    X.BinSort(9, ShiWei);
    std::cout<<"after BinSort, X is "<<X<<std::endl;
    X.BinSort(9, BaiWei);
    std::cout<<"after BinSort, X is "<<X<<std::endl;
    return 0;
}
示例#4
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;
      }
}