您的位置:学习中国 电脑维护 维护工具 正文
原作者:www 添加时间:2007-12-16 原文发表:2007-12-16 人气:824 来源:www

本文章共15679字,分29页,当前第23页,快速翻页:
 
-----------------------------------------------------------------------------------------------------------------------------------------------

本文提示:《C/C++ 笔试、面试题目大汇总(23)》是本站编辑们为广大网友精选的实用文章,本文阐述了关于文章的相关理论,相对来说专业性强,但是本文只是针对于某个问题提出的见解与论述,未必能辐射到相关问题的方方面面,所以本文处理问题的方法仅仅为您提供一些参考。更多问题请查阅学习中国网其他栏目哦.

-----------------------------------------------------------------------------------------------------------------------------------------------


#endif

39.文件中有一组整数,要求排序后输出到另一个文件中
答案:

#i nclude<iostream>

#i nclude<fstream>

using namespace std;


void Order(vector<int>& data) //bubble sort
{
int count = data.size() ;
int tag = false ; // 设置是否需要继续冒泡的标志位
for ( int i = 0 ; i < count ; i++)
{
for ( int j = 0 ; j < count - i - 1 ; j++)
{
if ( data[j] > data[j+1])
{
tag = true ;
int temp = data[j] ;
data[j] = data[j+1] ;
data[j+1] = temp ;
}
}
if ( !tag )
break ;
}
}


void main( void )
{
vector<int>data;
ifstream in("c:\\data.txt");
if ( !in)
{
cout<<"file error!";
exit(1);
}
int temp;
while (!in.eof())
{
in>>temp;
data.push_back(temp);
}
in.close(); //关闭输入文件流
Order(data);
ofstream out("c:\\result.txt");
if ( !out)
{
cout<<"file error!";
exit(1);
}
for ( i = 0 ; i < data.size() ; i++)
out<<data[i]<<" ";
out.close(); //关闭输出文件流
}

 
 

本文章更多内容<<上一页 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 - 21 - 22 - 23 - 24 - 25 - 26 - 27 - 28 - 29 - 下一页>>
本页地址
相关文章

解答一道传说是北大计算机面试的题目
计算机毕业 应聘面试题目大全
微软的招聘智力题(考考你自己)
收藏微软面试智力题 (附答案)
46家中外知名企业面试题目
面试考题大全
常见面试题目解析
IBM面试:以一个杯子即兴发挥
这些“怪题”20分钟考翻学子
用人单位以貌取人还出怪题

相关评论


本文章所属分类:首页 电脑维护 维护工具   维护工具