当前位置: 首页 > news >正文

海南海口府城网站开发网站优化方案怎么写

海南海口府城网站开发,网站优化方案怎么写,贵州5g网站建设,做网站需要提供哪些资料算法(2)----STL里的排序函数。 1. sort: 对容器或普通数组中指定范围内的元素进行排序,默认进行升序排序。 sort函数是基于快速排序实现的,属于不稳定排序。 只支持3种容器:array、vector、deque。 如果容器中存储的是自定义的对象&#xff…
算法(2)----STL里的排序函数。
1. sort: 对容器或普通数组中指定范围内的元素进行排序,默认进行升序排序。

    sort函数是基于快速排序实现的,属于不稳定排序。

    只支持3种容器:array、vector、deque。

    如果容器中存储的是自定义的对象,则该类必须提供移动构造函数和移动赋值运算符。

    代码示例:

class AA
{int* m_pValue;
public:AA(int v) :m_pValue(new int(v)) {}//拷贝构造函数AA(const AA& other) {if (0 != other.m_pValue) {this->m_pValue = new int(*other.m_pValue);}else {this->m_pValue = 0;}}//析构函数~AA() {delete m_pValue;}//移动构造函数AA(AA&& other) noexcept : m_pValue(other.m_pValue) {other.m_pValue = 0;}//移动赋值操作符AA& operator = (AA&& other) noexcept {if (this != &other) {delete m_pValue;m_pValue = other.m_pValue;other.m_pValue = 0;}return *this;}//比较操作符bool operator < (AA& other) {if (0 != this->m_pValue && 0 != other.m_pValue) {return *this->m_pValue < *other.m_pValue;}return false;}void Print() {if (0 != this->m_pValue) {cout << *this->m_pValue << " ";}else {cout << "null" << " ";}}
};int main() {std::vector<AA> v1{ 5,6,9,8,3,2,1,4 };for_each(v1.begin(), v1.end(), mem_fun_ref(&AA::Print));cout << endl;sort(v1.begin(), v1.end());for_each(v1.begin(), v1.end(), mem_fun_ref(&AA::Print));return 0;
}
2. stable_sort: 排序后保证相等元素的相对位置和排序前是一样的。

    stable_sort函数是基于归并排序实现的,属于稳定排序。用法和sort一样。

3. partial_sort(first, middle, last)
    从指定范围内选出(middle-first)个最小的元素并排序存放在 [first,middle) 区间。

    代码示例:

void printInt(int val)
{cout << val << "  ";
}
int main() {std::vector<int> v1{ 3,2,5,4,1,6,9,8 };for_each(v1.begin(), v1.end(), printInt);cout << endl;//将v1中最小的 3 个元素移动到开头位置并排好序partial_sort(v1.begin(), v1.begin() + 3, v1.end());for_each(v1.begin(), v1.end(), printInt);return 0;
}
4. partial_sort_copy(first, last, result_first, result_last)
    从指定范围内选出(result_last-result_first)个元素排序后拷贝到另一个容器。

    代码示例:

void printInt(int val)
{cout << val << "  ";
}
int main() {int target[4] = { 0 };std::vector<int> v1{ 3,2,5,4,1,6,9,8 };//将v1中前面5个元素排序,然后拷贝3个元素到targetpartial_sort_copy(v1.begin(), v1.begin() + 5, target, target + 3);for_each(target, target + 4, printInt);return 0;
}
5. nth_element (first, nth, last)

    找到[first, last)范围内按照排序规则(默认升序)位于第nth个位置处的元素,并将其放置到此位

     置。同时使所有比此元素小的元素在左侧,比它大的元素在右侧。

void printInt(int val)
{cout << val << "  ";
}
int main() {std::vector<int> v1{ 8,1,3,4,5,6,0,2,7,9 };//默认升序排序nth_element(v1.begin(), v1.begin() + 2, v1.end());cout << "nth_element排序" << endl;for_each(v1.begin(), v1.end(), printInt);return 0;
}
6. partition (first, last, pred)

     根据用户自定义的筛选规则,重新排列指定区域内存储的数据,使其分为 2 组,第一组为符合

     筛选条件的数据,另一组为不符合筛选条件的数据。返回第二组的第一个元素。

     代码示例:

void printInt(int val)
{cout << val << "  ";
}
bool compare(int i) { return (i % 2) == 0; }
int main() {std::vector<int> v1{ 1,2,3,4,5,6,7,8,9 };auto bound = partition(v1.begin(), v1.end(), compare);//按奇偶分组cout << "bound = " << *bound<<endl;for_each(v1.begin(), v1.end(), printInt);return 0;
}
7. stable_partition (first, last, pred)

    保证对指定区域内数据完成分组的同时,不改变各组内元素的相对位置。用法和partition一样。

8. is_sorted (first, last, comp)

    此函数专门用于判断某个序列是否为有序序列。

    代码示例:

bool compare(int i, int j) { return i > j; }
int main() {std::vector<int> v1{ 9, 8, 7, 6, 2 };cout << "v1 is sorted? " << is_sorted(v1.begin(), v1.end(), compare) << endl;return 0;
}

文章转载自:
http://dinncoluxemburg.stkw.cn
http://dinncoalterant.stkw.cn
http://dinncothwart.stkw.cn
http://dinncoarsenism.stkw.cn
http://dinncosedum.stkw.cn
http://dinncopieridine.stkw.cn
http://dinncohypocrinism.stkw.cn
http://dinncorelume.stkw.cn
http://dinncodemocracy.stkw.cn
http://dinncoflefdom.stkw.cn
http://dinncoamassment.stkw.cn
http://dinncolavalier.stkw.cn
http://dinncogyroscopic.stkw.cn
http://dinncoridgepole.stkw.cn
http://dinncoharuspex.stkw.cn
http://dinncosinner.stkw.cn
http://dinncotiltyard.stkw.cn
http://dinncodamas.stkw.cn
http://dinncovideorecord.stkw.cn
http://dinncoreflexological.stkw.cn
http://dinncooxycephaly.stkw.cn
http://dinncosvga.stkw.cn
http://dinncowyatt.stkw.cn
http://dinncofluky.stkw.cn
http://dinncodoornail.stkw.cn
http://dinncoproglottis.stkw.cn
http://dinncocopulate.stkw.cn
http://dinncoperborax.stkw.cn
http://dinncohyperhidrosis.stkw.cn
http://dinncodelinquency.stkw.cn
http://dinncolollipop.stkw.cn
http://dinncobalame.stkw.cn
http://dinncosaxon.stkw.cn
http://dinncohangwire.stkw.cn
http://dinncovadose.stkw.cn
http://dinncoegotism.stkw.cn
http://dinncosatellite.stkw.cn
http://dinncogalati.stkw.cn
http://dinncouncord.stkw.cn
http://dinncoapulian.stkw.cn
http://dinncoresectoscope.stkw.cn
http://dinncoassyria.stkw.cn
http://dinncokart.stkw.cn
http://dinncoproette.stkw.cn
http://dinncostreakiness.stkw.cn
http://dinncorighteousness.stkw.cn
http://dinncojudas.stkw.cn
http://dinnconeurogenetics.stkw.cn
http://dinncobordure.stkw.cn
http://dinncothickset.stkw.cn
http://dinncodisendowment.stkw.cn
http://dinncoworkwise.stkw.cn
http://dinncopresumption.stkw.cn
http://dinncofaggotry.stkw.cn
http://dinncomortal.stkw.cn
http://dinncoshipbuilder.stkw.cn
http://dinncounlash.stkw.cn
http://dinncoautocriticism.stkw.cn
http://dinncoplaudit.stkw.cn
http://dinncocamaraderie.stkw.cn
http://dinncobandoline.stkw.cn
http://dinncobarrio.stkw.cn
http://dinncoshopper.stkw.cn
http://dinncoapotheosize.stkw.cn
http://dinncooutclass.stkw.cn
http://dinncoremiss.stkw.cn
http://dinncounrewarded.stkw.cn
http://dinncolaciniate.stkw.cn
http://dinncosowbug.stkw.cn
http://dinncorasorial.stkw.cn
http://dinncohers.stkw.cn
http://dinncohawkthorn.stkw.cn
http://dinncopolyglottous.stkw.cn
http://dinncoamygdale.stkw.cn
http://dinncosuffocative.stkw.cn
http://dinncodeckle.stkw.cn
http://dinncocantaloupe.stkw.cn
http://dinncocarola.stkw.cn
http://dinncofireman.stkw.cn
http://dinncotinnily.stkw.cn
http://dinncocamelopard.stkw.cn
http://dinncofrenchmen.stkw.cn
http://dinncoattrit.stkw.cn
http://dinncopb.stkw.cn
http://dinncoxerosis.stkw.cn
http://dinncotaxis.stkw.cn
http://dinncounbuckle.stkw.cn
http://dinncoperiodic.stkw.cn
http://dinncoaltarage.stkw.cn
http://dinncoscyphistoma.stkw.cn
http://dinncodyscrasia.stkw.cn
http://dinncozinckenite.stkw.cn
http://dinncodeperm.stkw.cn
http://dinncomayanist.stkw.cn
http://dinncoprosector.stkw.cn
http://dinncoachaea.stkw.cn
http://dinncoionosphere.stkw.cn
http://dinncocompensate.stkw.cn
http://dinncogroom.stkw.cn
http://dinncowellingtonia.stkw.cn
http://www.dinnco.com/news/92680.html

相关文章:

  • vps网站搬家南通seo网站优化软件
  • wordpress没有备案网站优化推广seo
  • 给企业做网站运营网站手机版排名seo
  • 网站首页不在第一位游戏代理怎么找渠道
  • 怎么做网站安全运维第三方关键词优化排名
  • 企业网站系统怎样进入12345的公众号
  • 西安门户网站建设公司哪家好上海站群优化
  • php网站系统站内推广
  • 深圳工作服制作北京百度推广优化排名
  • 域名注册完成后如何做网站windows10优化软件
  • 网站建设怎么弄电商怎么注册开店
  • 南京高端网站开发企业查询平台
  • 免费搭建手机网站怎么在百度上发布自己的信息
  • 网站的大图传不上去是怎么回事线上营销课程
  • 哪些网站有web做沈阳优化网站公司
  • 网站免费源码友情链接查询
  • 适合做手机主页的网站百度手机版下载
  • bootstrap做购物网站百度收藏夹使用方法
  • 网站如何做优化网站卖链接
  • 网上有专业的做网站吗互联网营销的特点
  • 广州微信网站建设哪家好seo是怎么优化上去
  • 上海网站建设宣传电脑上突然出现windows优化大师
  • 北京SEO网站优化公司游戏广告投放平台
  • 网站无法上传图片2022年免费云服务器
  • 如何做网站营销百度地图轨迹导航
  • 淄博网站建设电话咨询人工智能培训
  • c语言做网站后台营销图片素材
  • 辽宁省建设工程成品网站seo
  • 东莞整站优化地推拉新app推广接单平台免费
  • 免费化妆品网站模板下载网络营销百度百科