Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- void Swap(int *a, int *b)// a := 8, b := 3
- {
- *a += *b; // a = 11, b = 3
- *b = *a - *b;// a = 11, b = 8
- *a -= *b;// a = 3, b = 8
- }
- // return <0 ha a előrébb van mint b
- // return 0 ha ekvivalensek a rendezés szempontjából
- // return >0 ha b előrébb van mint a
- int Min_Cmp(const void* _a,const void* _b)
- {
- int a = *(int*)_a, b = *(int*)_b;
- return a - b;
- }
- // Páros számokat rak előre, azon belül a kisebbeket.
- int Parity_Min_Cmp(const void* _a,const void* _b)
- {
- int a = *(int*)_a, b = *(int*)_b;
- if(abs(a)%2 == abs(b)%2) return a - b;
- return abs(a)%2 - abs(b)%2;
- }
- void Min_Sort(int* arr, int len, int(*cmp)(int,int))
- {
- int i, j;
- for(i = 0; i < len -1;++i )
- {
- int min_idx = i;
- for(j = i+1; j < len; ++j)
- {
- if(cmp(arr[j], arr[min_idx]) < 0) min_idx = j;
- }
- if(min_idx != i)
- Swap(arr + i, arr + min_idx);
- }
- }
- int main()
- {
- int arr[]={ 34, 45, 1 , 5, 15, 27, 88, -1,0 }, i;
- qsort(arr, 9, sizeof(int),Parity_Min_Cmp);
- for(i = 0; i < 9; ++i) printf("%d\t", arr[i]);
- printf("\n\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement