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

长春网站只长春网站制作做电商网站建设哪家好

长春网站只长春网站制作做,电商网站建设哪家好,咋样做网站,wordpress修改css和js引用C自学精简教程 目录(必读) 插入排序 每次选择未排序子数组中的第一个元素&#xff0c;从后往前&#xff0c;插入放到已排序子数组中&#xff0c;保持子数组有序。 打扑克牌&#xff0c;起牌。 输入数据 42 20 17 13 28 14 23 15 执行过程 完整代码 #include <iostream…

C++自学精简教程 目录(必读)

插入排序

每次选择未排序子数组中的第一个元素,从后往前,插入放到已排序子数组中,保持子数组有序。

打扑克牌,起牌。

输入数据

42 20 17 13 28 14 23 15

执行过程

完整代码

#include <iostream>
#include <cassert>
#include <vector>
using namespace std;void print_array(const char* msg, int* arr, int n)
{cout << msg << " ";for (int i = 0; i < n; i++){cout << arr[i] << " ";}cout << endl;
}
//swap two number
void Swap(int& a, int& b)
{int tmp = a; a = b; b = tmp;
}//将newValue插入到子数组arr中,arr的长度为length
void Insert(int* arr, int newValueindex, int newValue)
{// newValueindex=1     {arr[0]}    <== arr[1]           // newValueindex=2     {arr[0], arr[1]}    <== arr[2]// ......// newValueindex=n-1   {arr[0], arr[1],... arr[n-2]}    <== arr[n-1]// [a,   b,   c,   d]    e//  0              j     length   int j = newValueindex - 1;for (; j >= 0; j--){if (arr[j] > newValue){//move arr[j] to the next position,for newVaulearr[j + 1] = arr[j];}else{break;//break 发生时, j 的值可能是 0}}//发生了移动,j会停止在最后一个需要被移动的位置的前面一个位置if (j != newValueindex - 1){arr[j+1] = newValue;}
}void InsertSort(int* arr, int n)
{if (n <= 1){return;}//将下标为1的元素插入到{arr[0]}中//将下标为2的元素插入到{arr[0], arr[1]}中//......//将下标为n-1的元素插入到{arr[0], arr[1], arr[n-2]}中for (int i = 1; i < n; i++) {//将未排序序列中的第一个元素插入到已排序的序列中Insert(arr, i, arr[i]);//insert first element in unsorted list to the sorted listprint_array("one trip", arr, n);}
}void test(vector<int> arr)
{//输出原始序列print_array("original array:", arr.data(), arr.size());//执行排序,并输出排序过程InsertSort(arr.data(), arr.size());//输出排序后的列表print_array("after sorted:",arr.data(), arr.size());cout << endl;
}int main()
{test({ 1 });test({ 1 , 2 });test({ 2 , 1 });test( { 2 , 2 });test({ 42, 20, 17, 13, 28, 14, 23, 15 });test({ 1, 8, 3, 6, 5, 4, 7, 2 , 9 });test( { 8, 8, 6, 6, 7, 5, 5, 7, 9 , 9});return 0;
}

执行结果

original array: 1
after sorted: 1original array: 1 2
one trip 1 2
after sorted: 1 2original array: 2 1
one trip 1 2
after sorted: 1 2original array: 2 2
one trip 2 2
after sorted: 2 2original array: 42 20 17 13 28 14 23 15
one trip 20 42 17 13 28 14 23 15
one trip 17 20 42 13 28 14 23 15
one trip 13 17 20 42 28 14 23 15
one trip 13 17 20 28 42 14 23 15
one trip 13 14 17 20 28 42 23 15
one trip 13 14 17 20 23 28 42 15
one trip 13 14 15 17 20 23 28 42
after sorted: 13 14 15 17 20 23 28 42original array: 1 8 3 6 5 4 7 2 9
one trip 1 8 3 6 5 4 7 2 9
one trip 1 3 8 6 5 4 7 2 9
one trip 1 3 6 8 5 4 7 2 9
one trip 1 3 5 6 8 4 7 2 9
one trip 1 3 4 5 6 8 7 2 9
one trip 1 3 4 5 6 7 8 2 9
one trip 1 2 3 4 5 6 7 8 9
one trip 1 2 3 4 5 6 7 8 9
after sorted: 1 2 3 4 5 6 7 8 9original array: 8 8 6 6 7 5 5 7 9 9
one trip 8 8 6 6 7 5 5 7 9 9
one trip 6 8 8 6 7 5 5 7 9 9
one trip 6 6 8 8 7 5 5 7 9 9
one trip 6 6 7 8 8 5 5 7 9 9
one trip 5 6 6 7 8 8 5 7 9 9
one trip 5 5 6 6 7 8 8 7 9 9
one trip 5 5 6 6 7 7 8 8 9 9
one trip 5 5 6 6 7 7 8 8 9 9
one trip 5 5 6 6 7 7 8 8 9 9
after sorted: 5 5 6 6 7 7 8 8 9 9
http://www.ds6.com.cn/news/18448.html

相关文章:

  • wordpress首页视频主题上海网站seo招聘
  • 厚街手机网站制作东莞网站推广技巧
  • wordpress资源库宁波网站关键词优化代码
  • 小学生个人网站怎么做收录网站有哪些
  • 如何做网站收徒弟网站搜索引擎的网址有哪些
  • asp 建站百度论坛
  • 上海市网站建设公叿微信裂变营销软件
  • 哪里制作企业网站中央新闻频道直播今天
  • 上海金融网站制作网站制作公司好关键词排名查询网站
  • 杭州做网站软件seo实战培训费用
  • 做网站 用什么做数据库最好网店关键词怎么优化
  • 陕西 网站建设搜索排名优化软件
  • 个人婚礼网站设计今日最新头条新闻条
  • 利辛网站建设软件外包企业排名
  • 做营销网站那个好北京软件培训机构前十名
  • 网站开发学徒工作如何搜索推广代运营
  • 石家庄推广网站重庆seo搜索引擎优化优与略
  • 杭州做网站哪里好上海搜索引擎推广公司
  • b2c的电子商务的网站建设如何制作付费视频网站
  • 做存储各种环境信息的网站培训机构如何招生营销
  • 网站搭建流程图建设网站的步骤
  • 移动网站cms站长统计推荐
  • 学校如何建设网站首页宁波seo公司哪家好
  • 商务网站管理与建设引流软件下载站
  • 网站建设广告宣传素材企业官网定制设计
  • 西安单位网站制作河源seo
  • 做网站沧州我要下载百度
  • 企业做网站哪家便宜西安百度搜索排名
  • asp 做网站短期培训学什么好
  • wordpress站内链接一级域名二级域名三级域名的区别