#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>
using namespace std;
void Order(vector<int>& data)
{
int count = data.size();
int flag = false;
for(int i=0; i<count; i++)
{
for(int j=0; j<(count-1); j++)
{
if(data[j] > data[j+1])
{
flag = true;
int temp = data[j];
data[j] = data[j+1];
data[j+1] = temp;
}
}
if(!flag)
break;
}
return;
}
int main()
{
#ifdef __cplusplus
cout<<"c++"<<endl;
#else
cout<<"c"<<endl;
#endif
cout<<__LINE__<<endl;
cout<<__FILE__<<endl;
vector<int>data;
ofstream inn("./data.txt");
if(!inn)
{
cout<<"file error!!!"<<endl;
exit(1);
}
inn<<3<<' '<<4<<' '<<5<<' '<<1<<' '<<7;
inn.close();
ifstream in("./data.txt");
if(!in)
{
cout<<"file error!!!"<<endl;
exit(1);
}
int temp;
while(!in.eof())
{
in>>temp;
data.push_back(temp);
}
cout<<"排序前:"<<endl;
for(int i=0; i<data.size(); i++)
{
cout<<data[i]<<endl;
}
in.close();
Order(data);
ofstream out("./result.txt");
if(!out)
{
cout<<"file error!!!!"<<endl;
exit(1);
}
for(int i=0; i<data.size(); i++)
out<<data[i]<<" ";
cout<<"排序后:"<<endl;
for(int i=0; i<data.size(); i++)
{
cout<<data[i]<<endl;
}
out.close();
return 0;
}