当前位置: 首页>>代码示例>>C++>>正文


C++ Chain::Length方法代码示例

本文整理汇总了C++中Chain::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ Chain::Length方法的具体用法?C++ Chain::Length怎么用?C++ Chain::Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chain的用法示例。


在下文中一共展示了Chain::Length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _tmain

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;
}
开发者ID:huaijing,项目名称:Data--Structure,代码行数:41,代码来源:main.cpp

示例2: main

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;
      }
}
开发者ID:hzsunzixiang,项目名称:programming,代码行数:21,代码来源:chain.cpp


注:本文中的Chain::Length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。