#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <time.h>
#define NUM_CNT 10000000
#define FILE_NAME "num.txt"
void genNumber()
{
int i = ;
int *arr = (int*)malloc(sizeof(int) * NUM_CNT);
for(;i < NUM_CNT; ++i)
{
arr[i] = i;
}
FILE *fp = fopen(FILE_NAME,"w");
if(NULL == fp){printf("open %s failed\n",FILE_NAME);}
for(i = ;i < NUM_CNT; ++i)
{
if(i% == ){arr[i] = ;}
fprintf(fp,"%d ",arr[i]);
}
fclose(fp);
}
void readNum(int arr[])
{
int i = ;
FILE *fp = fopen(FILE_NAME,"r");
if(NULL == fp){printf("open %s failed\n",FILE_NAME);}
for(i = ;i < NUM_CNT; ++i)
{
fscanf(fp,"%d ",&arr[i]);
}
fclose(fp);
}
void dump(int *arr)
{
int i = ;
for(i = ;i < NUM_CNT; ++i)
{
printf("%d ",arr[i]);
}
printf("\n");
}
void del(int *arr,int len)
{
int i = ,j = ,t = ;
for(; i < len - ; ++i)
{
if(arr[i] == )
{
j = i + ;
while(j < len && arr[j]==)++j;
if(j < len)
{
t = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
}
}
}
void del1(int *arr,int len)
{
int i = ,j = ,t = ;
while(j < len && arr[j]==)++j;
if(j == len )return;
for(; i < len - && j < len; ++i)
{
if(arr[i] == )
{
t = arr[i];
arr[i] = arr[j];
arr[j] = t;
while(j < len && arr[j]==)++j;
}
}
}
int main()
{
int t = ;
int *arr= (int*)malloc(sizeof(int) * NUM_CNT);
genNumber();
readNum(arr);
//dump(arr);
t = clock();
del1(arr,NUM_CNT);
printf("use time:%lu ms\n",clock() - t);
//dump(arr);
return ;
}