所以這時,就讓我找到了Visual Studio的擴充功能「Visual Studio Bitbucket Extension」啦!
安裝新的擴充功能 |
搜尋Visual Studio Bitbucket Extension |
PM2011,我的外插式硬碟~
安裝新的擴充功能 |
搜尋Visual Studio Bitbucket Extension |
void qsort(void *base,
size_t n,
size_t size,
int ((compare) (const void *, const void *))
#include <stdio.h>#include <stdlib.h>#define ARRAY_MAX 5typedef struct _Classmate{int chinese, english, math;}Classmate;/*傳回-1代表 a < b傳回 0代表 a = b傳回 1代表 a > b*/int compare(const Classmate *a, const Classmate *b){/* 總分比較 */if (a->chinese + a->english + a->math !=b->chinese + b->english + b->math)return (a->chinese + a->english + a->math <b->chinese + b->english + b->math) ? -1 : 1;/* 先比國文 */if (a->chinese != b->chinese)return (a->chinese < b->chinese) ? -1 : 1;/* 在比英文 */if (a->english != b->english)return (a->english < b->english) ? -1 : 1;/* 最後數學 */if (a->math != b->math)return (a->math < b->math) ? -1 : 1;/* 全部相等 */return 0;}void printAll(Classmate *classmate){int i;for (i = 0; i < ARRAY_MAX; i++){printf("[%02d] %3d + %3d + %3d = %3d\n",i + 1,classmate[i].chinese,classmate[i].english,classmate[i].math,classmate[i].chinese + classmate[i].english + classmate[i].math);}}int main(int argc, char *argv[]){Classmate classmate[ARRAY_MAX] = {{ 50, 75, 90 },{ 30, 46, 50 },{ 100, 80, 60 },{ 55, 55, 80 },{ 95, 100, 70 }};printf("====== 排序前 ======\n");printAll(classmate);qsort(classmate,ARRAY_MAX,sizeof(Classmate),compare);printf("\n====== 排序後 ======\n");printAll(classmate);return 0;}
====== 排序前 ======
[01] 50 + 75 + 90 = 215
[02] 30 + 46 + 50 = 126
[03] 100 + 80 + 60 = 240
[04] 55 + 55 + 80 = 190
[05] 95 + 100 + 70 = 265
====== 排序後 ======
[01] 30 + 46 + 50 = 126
[02] 55 + 55 + 80 = 190
[03] 50 + 75 + 90 = 215
[04] 100 + 80 + 60 = 240
[05] 95 + 100 + 70 = 265