예제 #1
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;
}
예제 #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;
      }
}