#include <stdio.h>#include<malloc.h>#include<stdlib.h>#include<time.h>#defineNum_cnt 10000000#definefile_name "Num.txt"voidGennumber () {inti =0; 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 =0; i < num_cnt; ++i) {if(i%7==0) {Arr[i] =0;} fprintf (FP,"%d", Arr[i]); } fclose (FP);}voidReadnum (intarr[]) { inti =0; FILE*FP = fopen (file_name,"R"); if(NULL = = fp) {printf ("Open%s failed\n", file_name);} for(i =0; i < num_cnt; ++i) {fscanf (FP),"%d",&Arr[i]); } fclose (FP);}voidDumpint*arr) { inti =0; for(i =0; i < num_cnt; ++i) {printf ("%d", Arr[i]); } printf ("\ n");}voidDelint*arr,intLen) { inti =0, j =0, t =0; for(; i < Len-1; ++i) {if(Arr[i] = =0) {J= i +1; while(J < Len && arr[j]==0)++J; if(J <Len) {T=Arr[i]; Arr[i]=Arr[j]; ARR[J]=T; } } }}voidDel1 (int*arr,intLen) { inti =0, j =0, t =0; while(J < Len && arr[j]==0)++J; if(j = len)return; for(; i < Len-1&& J < Len; ++i) {if(Arr[i] = =0) {T=Arr[i]; Arr[i]=Arr[j]; ARR[J]=T; while(J < Len && arr[j]==0)++J; } }}intMain () {intt =0; 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 0;}
C do not change the order, the original site culling array of 0 elements