#include <iostream>using namespace std;int power[] = {15,25,90,23,10}, temp;int numslen = sizeof(power) / sizeof(int); //计算实际长度int min = power[0]; //假设最小值是数组的第一个元素int minIndex = 0; //最小值的初始下标是0void spot() //排序函数{for (int i = 0; i < numslen; i++){min = power[i];//假设第i个元素是最小值minIndex = i;for (int j = i + 1; j < numslen; j++){if(power[j]<min){min = power[j];minIndex = j;}}if (minIndex > i){temp = power[minIndex];power[minIndex] = power[i];power[i] = temp;}}cout << "排序后:";for (int i = 0; i < numslen; i++)cout << power[i]<<",";}int main() //插入数后排序{int insert,insertIndex;cout << "请输入要插入的数:" << endl;cin >> insert;for (int i = 0; i < numslen; i++){if (insert > power[i]){insertIndex = i;break;}}for (int i = numslen - 1; i >= insertIndex; i--){power[i + 1] = power[i];}power[insertIndex] = insert;numslen++;cout << "插入数值后排序结果为" <<spot(insert) << endl;return 0;}
1 回答
红糖糍粑
TA贡献1815条经验 获得超6个赞
方法1 mcc 生成cpp文件方式
1、设置项目编译选项
首先建立一个新的项目,或者打开一个已有的项目,然后选择菜单:
Project-> Settings-> C/C++
Category:Preprocessor
Preprocessor definitions:
添加: MSVC,IBMPC,MSWIND
Category: Precompiled Headers
选择: Automatic use of precompiled headers
Through header: stdafx.h
2、调设置项目连接选项
首先要从下面几个函数定义文件(*.def)生成相应的导入库文件(*.lib)
libmmfile.def
libmcc.def
libmatlb.def
libmx.def
libmat.def
- 1 回答
- 0 关注
- 119 浏览
添加回答
举报
0/150
提交
取消