#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{srand((size_t)time(NULL));FILE* fp=fopen("d:/data.txt","w");if(!fp) return -1;for(int i=0;i<1000;i++)fprintf(fp,"%d\n",rand()%256);fclose(fp);return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define SIZE 1000void BubbleSort(int* src,int len)
{for(int i=0;i<len-1;i++){for(int j=0;j<len-1-i;j++){if(src[j]>src[j+1]){int temp=src[j];src[j]=src[j+1];src[j+1]=temp;}}}
}int main()
{FILE* fp1=fopen("d:/data.txt","r");FILE* fp2=fopen("d:/sort.txt","w");if(!fp2||!fp2)return -1;int* arr=(int*)malloc(sizeof(int)*SIZE);for(int i=0;i<SIZE;i++)fscanf(fp1,"%d\n",&arr[i]);BubbleSort(arr,SIZE);for(int i=0;i<SIZE;i++)fprintf(fp2,"%d\n",arr[i]);free(arr);fclose(fp1);fclose(fp2);return 0;}