/* 快速排序法的递归处理 */ void q_sort(FILE *fp,long int left,long int right) { char partition; //分割元素 int i,j; if(left < right) //是否继续分割 { i = left; //分割的最左 j = right + 1; //分割的最右 partition = get_char(fp,left); //取第一个元素 do { do //从左往右找 { i++; }while(get_char(fp,i) < partition); do { j--; }while(get_char(fp,j) > partition); if(i < j) swap_char(fp,i,j); //交换数据 }while(i < j); swap_char(fp,j,left); //交换数据 q_sort(fp,left,j-1); //快速排序递归调用 q_sort(fp,j+1,right); //快速排序递归调用 } }
void swap(char* str) { int i = -1; while (*(str + ++i)){;} std::cout<<i<<std::endl; if(i%2 == 0) { i /= 2; str = str+i; for (i = 0;*(str+i);++i) { swap_char(*(str+i), *(str-1-i)); } } else { i /= 2; i += 1; str = str+i; for (i = 0;*(str+i);++i) { //std::swap(*(str+i), *(str-2-i)); swap_char(*(str+i), *(str-2-i)); } } }
int main(void) { int a = 3; int b = 5; printf("%d\t%d\n", a, b); swap_int(&a, &b ); printf("%d\t%d\n", a, b); char s1[] = "a"; char s2[] = "b"; printf("%s\t%s\n", &s1[0], &s2[0]); swap_char(s1, s2 ); printf("%s\t%s\n", &s1[0], &s2[0]); char s3[] = "abcdefg"; printf("%s\n", &s3[0]); reverseString(s3); printf("%s\n", &s3[0]); return 0; }
char* r_reverse(char* str, int len, int i) { if (i >= len / 2) return str; swap_char(&str[i], &str[len - i - 1]); return r_reverse(str, len, i + 1); }
char *reverse(char *num) { int len, i; len = strlen(num) - 1; for(i = 0; i < (len + 1) / 2; ++i) { swap_char(num, i, len - i); } return num; }
void init_sensor_orientation() { init_sensor_orientation_default(); if(config.axis_reverse_z){ // flip over roll sensor_def.acc[YAW].dir *= -1; sensor_def.acc[ROLL].dir *= -1; sensor_def.gyro[PITCH].dir *= -1; sensor_def.gyro[YAW].dir *= -1; } if(config.axis_swap_xy){ // swap gyro axis swap_char(&sensor_def.gyro[ROLL].idx, &sensor_def.gyro[PITCH].idx); swap_int(&sensor_def.gyro[ROLL].dir, &sensor_def.gyro[PITCH].dir); // swap acc axis swap_char(&sensor_def.acc[ROLL].idx, &sensor_def.acc[PITCH].idx); swap_int(&sensor_def.acc[ROLL].dir, &sensor_def.acc[PITCH].dir); } }
void initSensorOrientation() { initSensorOrientationDefault(); if (config.axisReverseZ) { // flip over roll sensorDef.Acc[axisYAW].dir *= -1; sensorDef.Acc[axisROLL].dir *= -1; //sensorDef.Acc[axisPITCH].dir *= -1; //sensorDef.Gyro[axisPITCH].dir *= -1; sensorDef.Gyro[axisROLL].dir *= -1; sensorDef.Gyro[axisYAW].dir *= -1; sensorDef.Mag[axisYAW].dir *= -1; //sensorDef.Mag[axisROLL].dir *= -1; sensorDef.Mag[axisPITCH].dir *= -1; } if (config.axisSwapXY) { // swap gyro axis swap_char(&sensorDef.Gyro[axisROLL].idx, &sensorDef.Gyro[axisPITCH].idx); swap_int(&sensorDef.Gyro[axisROLL].dir, &sensorDef.Gyro[axisPITCH].dir); //sensorDef.Gyro[axisPITCH].dir *= -1; // try and error ;-) sensorDef.Gyro[axisROLL].dir *= -1; // swap acc axis swap_char(&sensorDef.Acc[axisROLL].idx, &sensorDef.Acc[axisPITCH].idx); swap_int(&sensorDef.Acc[axisROLL].dir, &sensorDef.Acc[axisPITCH].dir); sensorDef.Acc[axisROLL].dir *= -1; swap_char(&sensorDef.Mag[axisROLL].idx, &sensorDef.Mag[axisPITCH].idx); swap_int(&sensorDef.Mag[axisROLL].dir, &sensorDef.Mag[axisPITCH].dir); sensorDef.Mag[axisROLL].dir *= -1; } //compass.set_transformation }
void reverseString(char *s) { char *a, *b; int i; int n = strlen(s); for ( i = 0; i < n/2; i++) { a = s + i; b = s + n-1-i; swap_char(a,b); } }
/************************************************************* * Sorts characters according to counts. At the end * * make sure that *c1 keeps most frequent used letter, *c3 * * keeps least frequent used letter and *c2 keeps remained * * letter * *************************************************************/ void sort(char *a, int a_num, char *b, int b_num, char *c, int c_num) { if(a_num<b_num) { swap_int(&a_num, &b_num); swap_char(b,a); } if(c_num>a_num) { swap_int(&c_num, &a_num); swap_char(a,c); } if(c_num>b_num) { swap_int(&c_num, &b_num); swap_char(b,c); } }
void bubblesort(t_info *info, int filec, int (*cmp)(time_t, time_t)) { int i; int swapped; i = 0; swapped = 1; while (swapped) { swapped = 0; while (i + 1 < filec) { if (cmp(info->stats[i]->st_mtime, info->stats[i + 1]->st_mtime)) { swap_char(&info->file[i], &info->file[i + 1]); swap_char(&info->list[i], &info->list[i + 1]); swap_stat(&info->stats[i], &info->stats[i + 1]); swapped = 1; } i++; } i = 0; } }
/* Unicode 5.2.0 D109 Canonical Ordering for a sequence of code points * that all have Canonical_Combining_Class > 0 */ static void canonical_reorder_sequence(uint32_t * a, size_t len) { size_t i, j; if (len <= 1) return; for (i = 1; i < len; i++) { for (j = i; j > 0 && _wind_combining_class(a[j]) < _wind_combining_class(a[j-1]); j--) swap_char(&a[j], &a[j-1]); } }
void str_revers_string(char str[]) { int i,j; i = 0; j = str_lunghezza_stringa(str) - 1; while ( j > i) { swap_char(&str[j], &str[i]); i++; j--; } return; }
void reverse_string (char *str, int from, int to) { while (from < to) swap_char (&(str[from++]), &(str[to--])); }