Algorithm, in the school when the grasp of the weak, and now still have to go.
NSMutableArray *dateMutablearray = [@[] mutableCopy];
NSArray *array1 = @[@"1",@"2",@"3", @"3",@"4",@"5",@"7",@"9",@"9", @"11",];NSMutableArray *array = [NSMutableArray arrayWithArray:array1];for(inti = 0; i < array.count; i ++) { NSString *string = array[i]; NSMutableArray *tempArray = [@[] mutableCopy]; [tempArray addObject:string]; for(intj = i+1; j < array.count; j ++) { NSString *jstring = array[j]; NSLog(@"jstring:%@",jstring); if([string isEqualToString:jstring]) { NSLog(@"jvalue = kvalue"); [tempArray addObject:jstring]; } } if([tempArray count] > 1) { [array removeObjectsInArray:tempArray]; i -= 1; //去除重复数据 新数组开始遍历位置不变 }}
Worst-of-the-nodups algorithm: de-heavy, unrelated to array whether public void () {//} iterates over for (int i=0; i<nelems-1; i++) {//with each subsequent comparison for (j=i+ 1; j<nelems; J + +) {//if equal, all subsequent entries move forward, total-1 if (A[i]==a[j]) {for (k=j+1; k<nelems; k++) { A[J] = a[j+1]; nelems--; }}}}} put the following different forward public void nodups () {//array from small to large this.insertionsort (); int i=0; The first pointer int j=0; The second pointer for (j=1; j<nelems;j++) {//encounters the same skip, the difference is added to the front if (A[j]!=a[i]) {A[++i]=a[j]} } nelems = i+1;} Mark the duplicate as-1, assuming there is no negative public void nodups () {//array from large to small arrange this.insertionsort (); Final int FLAG =-1; Repeating number marker int holdnumber; Number of numbers marked//Find duplicates and mark for (int i=0; i<nelems; i++) {for (int j=i+1; j<nelems; J + +) {if (a[i]==a [j]) {A[j] = FLAG; holdnumber++; }}}//Handle tagged numbers//ideas and the first one as int i=0; Index bit for (int j=1; j<nelems; J + +) {//The first cannot be a repetition//find the first mark bit if (A[j]==flag && i==0) {i = J; }else if (A[j]!=flag && i!=0) {//logic with the second algorithm a[i] = a[j]; i++; }} Nelems-= Holdnumber;}
iOS Development-several algorithms for sequential array de-weight