文件中有一组整数,要求排序后输出到另一个文件中
来源:互联网 发布:去哪里找淘宝摄影团队 编辑:程序博客网 时间:2024/06/03 16:00
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
void Order(vector<int>&data)
{
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()
{
vector<int>data;
ifstream in("C:\\Users\\qhsong\\Desktop\\1.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:\\Users\\qhsong\\Desktop\\2.txt");
if (!out)
{
cout << "file error!";
exit(1);
}
for (int i = 0; i < data.size(); i++)
out << data[i] << "";
out.close(); //关闭输出文件流
}
#include<fstream>
#include<vector>
using namespace std;
void Order(vector<int>&data)
{
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()
{
vector<int>data;
ifstream in("C:\\Users\\qhsong\\Desktop\\1.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:\\Users\\qhsong\\Desktop\\2.txt");
if (!out)
{
cout << "file error!";
exit(1);
}
for (int i = 0; i < data.size(); i++)
out << data[i] << "";
out.close(); //关闭输出文件流
}
1 0
- 文件中有一组整数,要求排序后输出到另一个文件中
- 文件中有一组整数,要求排序后输出到另一个文件中
- 文件中有一组整数,要求排序后输出到另一个文件中
- 文件中有一组整数,要求排序后输出到另一个文件中
- 文件中有一组整数,要求排序后输出到另一个文件中
- 文件中有一组整数,要求排序后输出到另一个文件中
- 整型数组处理算法(二)文件中有一组整数,要求排序后输出到另一个文件中
- 源文件中有一组整数,排序后输出到另一个文件
- 源文件中有一组整数,排序后输出到另一个文件
- C++面试题:把文件中的一组整数排序后输出到另一个文件中。
- 把文件中的一组整数排序后输出到另一个文件中(c/c++)
- 文件中有一整数数组,要求排序后输出到另一文件(C++)
- 从文件中读取数据,排序之后输出到另一个文件中
- 从文件中读取数据,排序之后输出到另一个文件中
- 文件中读取数字并排序输出到另一个文件中
- 有两个磁盘文件 A,B 各放一行字母,要求把两文件信息合并(按字母排序),输出到C 中
- 通过缓冲流把一个文本文件中的字符串排序后输入到另一个文件中
- 将两个文件的内容排序后输出到一个文件中
- Android 5.0 Material主题 ProgressBar颜色更改。
- 虚拟币研发与运营的难度在哪里?
- maven 打包 时出现非法字符: /65279错误
- 过滤器和拦截器的区别
- MySQL命令行简介
- 文件中有一组整数,要求排序后输出到另一个文件中
- Java基础第二章
- 中国剩余定理
- 什么是序列化,为什么要序列化。
- Python 入门学习笔记1
- Cookie与Session的区别
- java开发环境搭建
- 抽象类与接口
- 使用sublime结合sshfs在windows下进行linux服务器远程同步开发