⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prg6_3.cpp

📁 数据结构c++语言描述stl版 威廉兄弟的好书,值得看,这是配书代码
💻 CPP
字号:
// File: prg6_3.cpp
// the program declares an unordered integer array,
// arr, containing duplicate values. it builds the
// ordered list, intList, by inserting each element
// of arr into the list using insertOrder(). calling
// removeDuplicates() transforms intList into a list
// of unique values. the program uses writeSeqList()
// to output the list before and after removing
// duplicates

#include <iostream>
#include <list>

#include "d_listl.h"		// for insertOrder() and removeDuplicates()
#include "d_util.h"		// for writeList()

using namespace std;

int main()
{
	// declare an unordered array with duplicate values
	int arr[] = {7, 2, 2, 9, 3, 5, 3, 9, 7, 2}, i;
	int arrSize = sizeof(arr)/sizeof(int);
	list<int> intList;

	// build the ordered list using elements from the array 
	for (i = 0; i < arrSize; i++)
		insertOrder(intList, arr[i]);

	// output the ordered list with duplicates
	cout << "Ordered list with duplicates: ";
	writeList(intList);

	// remove duplicate values
	removeDuplicates(intList);

	// output the ordered list that has no duplicates
	cout << "Ordered list without duplicates: ";
	writeList(intList);

	return 0;
}

/*
Run:

Ordered list with duplicates: 2  2  2  3  3  5  7  7  9  9
Ordered list without duplicates: 2  3  5  7  9
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -