起泡排序
来源:互联网 发布:nb物理实验室软件 编辑:程序博客网 时间:2024/04/25 12:39
#include<iostream> #include<vector> using namespace std; class BubbleSort { public: void Input(); //数据输入 void Insert(); //直接插入排序 void Output();//数据输出 private: vector<int> vec;//vec[0]作为监视哨 }; void BubbleSort::Input() { int a; cout<<"第一个输入的数据元素作为监哨值,不作为表中的排序元素:"<<endl; while(cin>>a) { vec.push_back(a); }//while }//Input void BubbleSort::Insert() { int i,j; for(i=vec.size()-1;i>1;i--){for(j=1;j<i;j++){if(vec[j]>vec[j+1])//两个记录交换{vec[0]=vec[j+1];vec[j+1]=vec[j];vec[j]=vec[0];}//if}//for_j}//for_i}//Insert void BubbleSort::Output() { vector<int>::iterator it=vec.begin()+1; while(it!=vec.end()) { cout<<*it<<" "; it++; }//while }//Output void main() { BubbleSort BS; BS.Input(); BS.Insert(); BS.Output(); }//main
0 0
- 起泡排序
- 起泡排序
- 起泡排序
- 起泡排序
- 起泡排序
- 起泡排序
- 起泡排序
- 起泡排序
- 起泡排序
- 起泡排序
- 起泡排序
- 起泡排序
- 起泡排序
- 起泡排序
- 起泡排序/快速排序
- 排序:起泡排序法
- c++实现起泡排序
- 快速,起泡,选择排序
- notepad++ 正则
- TLB和cache的关系
- C# listView sample
- Linux ld链接问题
- java类读写文件到指定位置(项目发布到tomcat上的指定位置)
- 起泡排序
- 您是从何时开始关注 Go 语言?是什么原因促使你们团队决定使用 Go 语言?以及是什么原因促成了《Go语言编程》这本书呢?
- java反射
- HibernateDaoSupport 无法保存数据到数据库,并且不报错
- Spring MVC POST中文乱码解决方案
- 最大堆的插入,删除和初始化
- 【转】TCP/IP协议与UDP协议的区别
- 【Struts2】⑤常量定义
- Next Permutation