My FAQ,最新最全的IT技术FAQ
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 未整理篇 | 技术讨论
  当前位置: > 操作系统 > Linux > Linux综合
程序
作者:未知 时间:2005-09-13 22:16 出处:Blog.ChinaUnix.net 责编:My FAQ
              摘要:程序
nothing!!!!

#include<cstdlib>
#include<iostream>
#include<fstream>
//#include<vector>
using namespace std;

void swapInt(int &a,int &a2)
 {
 int temp=a;
 a=a2;
 a2=temp;
 }
void creatFile(char *file)
 {
 ofstream fout; 
    fout.open(file,ios::out);
 int tempRand;
 for(int i=0;i<50;i++)
  {
  tempRand=(int)rand()/(RAND_MAX/100);
  if(tempRand)
   fout<<tempRand<<endl;
  else
   i--;
  }
 fout.close();
 }
void readFile(char *file,int arr[50])
 {
 ifstream fin;
 fin.open(file,ios::in );
 for(int j=0;j<50;j++)
  {
  fin>>arr[j];
  }
 fin.close();
 }
void bubbleSort(int a[], int n=50)//冒泡排序法
 {
 bool change;
 for(int i=n-1,change=true;i>=1&&change;i--)
  {
  change=false;
  for(int j=0;j<i;j++)
   if(a[j]>a[j+1])
    {
    swapInt(a[j],a[j+1]);
    change=true;
    }
  }
 }
int main()
 {
char *file="f:\test228.txt";
int a[50];
srand(1);
 creatFile(file);
 readFile(file,a);
 bubbleSort(a);
for(int i=0;i<50;i++)
  {
  cout<<a[i]<<endl;
  
  }
/* 
 char *file2="f:\test2280.txt";
 int a2[50];
srand(2);
creatFile(file2);
readFile(file2,a2);
for(int i=0;i<50;i++)
  {
  cout<<a2[i]<<endl;
  }
  */
 return 0;
 }

 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 myfaq.com.cn All rights reserved. www.myfaq.com.cn 版权所有