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


C++ ItemType::toString方法代码示例

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


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

示例1: main

int main()
{
	clock_t start = clock();
	int const DELETE_CT = 2;
	int const PRINTSIZE = 5;
	int const HOWMANY = 20;  // How many values to read from each file.  If HOWMANY = 0, read all values.
	// SkewHeap pq1("SkewHeap PQ1");
	// LeftistHeap pq1("Leftist PQ1");
	/*PQHeap pq1("Heap PQ1", 6000);
	PQHeap pq2("Heap PQ2", 6000);
	PQHeap pq3("Heap PQ3", 6000);
	PQHeap pq4("Heap PQ4", 6000);
	PQHeap pq5("Heap PQ5", 6000);
	PQHeap pq6("Heap PQ6", 6000);*/
	SkewHeap pq1("SkewHeap PQ1");
	SkewHeap pq2("SkewHeap PQ2");
	SkewHeap pq3("SkewHeap PQ3");
	SkewHeap pq4("SkewHeap PQ4");
	SkewHeap pq5("SkewHeap PQ5");
	SkewHeap pq6("SkewHeap PQ6");
	/*Leftist pq1("LeftistHeap PQ1");
	Leftist pq2("LeftistHeap PQ2");
	Leftist pq3("LeftistHeap PQ3");
	Leftist pq4("LeftistHeap PQ4");
	Leftist pq5("LeftistHeapPQ5");
	Leftist pq6("LeftistHeapPQ6");/**/
	
	ifstream fin;
	fin.open("Prog5In.txt");
	assert(fin);

	insertNext(pq1, fin, HOWMANY);
	insertNext(pq2, fin, HOWMANY);
	insertNext(pq3, fin, HOWMANY);
	insertNext(pq4, fin, HOWMANY);
	insertNext(pq5, fin, HOWMANY);
	insertNext(pq6, fin);

	cout << pq1.toString(PRINTSIZE);
	ofstream fout;
	fout.open("prog5out.txt");
	cout << pq1.toString(PRINTSIZE);

	for (int ct = 0; ct < DELETE_CT && !pq1.isEmpty(); ct++){
		ItemType big = pq1.deleteMax();
		fout << " ** DELETED " << big.toString() << endl;
		cout << " ** DELETED " << big.toString() << endl;
		cout << pq1.toString(PRINTSIZE);
	};
	for (int ct = 0; ct < DELETE_CT && !pq2.isEmpty(); ct++) {
		ItemType big = pq2.deleteMax();
		fout << " ** DELETED " << big.toString() << endl;
		cout << " ** DELETED " << big.toString() << endl;
	};
	cout << "Before merge \n" << pq1.toString(PRINTSIZE) << endl;
	fout << "Before merge \n" << pq1.toString(PRINTSIZE) << endl;
	cout << "Before merge \n" << pq2.toString(PRINTSIZE) << endl;
	fout << "Before merge \n" << pq2.toString(PRINTSIZE) << endl;

	pq1.merge(&pq2);

	cout << "After merge \n" << pq1.toString(PRINTSIZE) << endl;
	fout << "After merge \n" << pq1.toString(PRINTSIZE) << endl;
	cout << "After merge \n" << pq2.toString(PRINTSIZE) << endl;
	fout << "After merge \n" << pq2.toString(PRINTSIZE) << endl;
	pq3.merge(&pq4);
	cout << "After merge 3 and 4 \n" << pq3.toString(PRINTSIZE) << endl;
	pq5.merge(&pq6);
	cout << "After merge 5 and 6 \n" << pq5.toString(PRINTSIZE) << endl;
	pq1.merge(&pq3);
	cout << "After merge 1 and 3\n" << pq1.toString(PRINTSIZE) << endl;
	pq1.merge(&pq5);
	cout << "After merge 1 and 5\n" << pq1.toString(PRINTSIZE) << endl;
	clock_t time = clock() - start;
	cout << "Elapsed time = " << ((float)time) / CLOCKS_PER_SEC << endl;
	fout << "Elapsed time = " << ((float)time) / CLOCKS_PER_SEC << endl;
	fout.close();
}
开发者ID:jenniferballing,项目名称:CS3Program5,代码行数:78,代码来源:TestPQ,.cpp


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