题目如下: A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance…
// VectorSort.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <vector> #include <algorithm> //先自定义一个结构体 struct Test { int member1; int member2; }; //自定义排序函数 bool So…
前天要做一个对C++ STL的vector容器做一个排序操作,之前一直把vector当做一个容量可自动变化的数组,是的,数组,所以打算按照对数组进行排序的方法:用快速排序或是冒泡排序等算法自己写一个排序的函数.后来觉得STL这么强大,应该有它自己的排序方法(没有好好学习啊),然后就去google了一下,果然有,而且可以自定义排序的函数,太强大了(而且效率应该比我自己写的要好吧). // VectorSort.cpp : Defines the entry point for the consol…
一.解释: vector(向量):是一种顺序容器,事实上和数组差不多,但它比数组更优越.一般来说数组不能动态拓展,因此在程序运行的时候不是浪费内存,就是造成越界.而vector正好弥补了这个缺陷,它的特征是相当于可分配拓展的数组,它的随机访问快,在中间插入和删除慢,但在末端插入和删除快. 二.用法: 1.头文件 #include <vector> 2.定义方式 a) vector<int>v1;//vector元素为 int 型 b) vector<string>v2…