prg15_1.cpp

来自「这是数据结构和算法的国外经典书籍.清华大学出版社出版的<数据结构C++语言」· C++ 代码 · 共 52 行

CPP
52
字号
#ifdef _MSC_VER
// disable warning messages that identifier was truncated
// to 'number' characters in the debug information
#pragma warning(disable:4786)
#endif	// _MSC_VER

// File: prg15_1.cpp
// the program initializes a vector of integers and a vector of strings.
// it then applies the function mergeSort() to each vector and outputs
// the result 

#include <iostream>
#include <string>
#include <vector>

#include "d_sort.h"		// for mergeSort()
#include "d_util.h"		// for writeContainer()

using namespace std;

int main()
{
	// create an array of integers and of strings for the sort
	int intList[] = {25, 10, 7, 19, 3, 48, 12, 17, 56, 30, 21};

	string strList[] = {"Dallas","Akron","Wausau","Phoenix",
								"Fairbanks","Miami"};

	vector<int> vIntList(intList, intList+11);
	vector<string> vStrList(strList,strList+6);

	// sort and the output each vector 
	mergeSort(vIntList, 0, vIntList.size());
	cout << "Sorted integers: ";
	writeContainer(vIntList.begin(), vIntList.end(), "  ");
	cout << endl;

	mergeSort(vStrList, 0, vStrList.size());
	cout << "Sorted strings:  ";
	writeContainer(vStrList.begin(), vStrList.end() , "  ");
	cout << endl;

	return 0;
}

/*
Run:

Sorted integers: 3  7  10  12  17  19  21  25  30  48  56
Sorted strings:  Akron  Dallas  Fairbanks  Miami  Phoenix  Wausau
*/

⌨️ 快捷键说明

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