- //
- // main.m
- // C_Lession_10
- //
- // Created by Ben_22 on 14-5-20.
- // Copyright (c) 2014年 Ben_22. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- void godSort(voidvoid *pArr, size_t n, size_t size ){
- voidvoid *temp = malloc(size);
- for (int i = 0 ; i<n-1; i++) {
- for (int j = 0; j<n-i-1; j++) {
- if (memcmp(pArr+size*j, pArr+size*(j+1),size)<0) {
- memcpy(temp, pArr+size*j, size);
- memcpy(pArr+size*j, pArr+size*(j+1), size);
- memcpy(pArr+size*(j+1), temp, size);
- }
- }
- }
- free(temp);
- }
- int main(int argc, const charchar * argv[])
- {
- int arr[10] = {1,2,3,4,5,6,7,8};
- int arr1[10] = {1,2};
- int result = memcmp(arr, arr1, 8);
- printf( "%d\n",result);
- godSort(arr, 10, 4 );
- for (int i =0 ; i<10; i++) {
- printf("%d ", *(arr+i));
- }
- return 0;
- }
万能冒泡排序
最新推荐文章于 2024-06-10 20:54:20 发布