[討論] c++ qsort 的問題
請問一個 我有一個array 1 到n 我呼叫qsort 這個內建的函式 可是sort 出來
好像是 3-n 排序過 array[1] array[2] 是一個有的沒有的數 我是哪裡寫錯了
#include<stdio.h>
#include<algorithm>
#define MAX_SIZE 512
int compare(const void *a,const void *b)
{
int *ta=(int *)a;
int *tb=(int *)b;
if(*ta>=*tb)
return 1;
return -1;
// return ( *(int*)a - *(int*)b );
}
int _tmain(int argc, _TCHAR* argv[])
{
int n;
scanf("%d",&n);
int correct_ans[MAX_SIZE]={0};
int student_ans[MAX_SIZE]={0};
for(int i=1;i<=n;i++)
scanf("%d",&student_ans[i]);
qsort(student_ans,n+1,sizeof(student_ans),compare);
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.168.187.223
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1411238820.A.2A6.html
推
09/21 02:50, , 1F
09/21 02:50, 1F
→
09/21 03:33, , 2F
09/21 03:33, 2F
→
09/21 04:03, , 3F
09/21 04:03, 3F
→
09/21 05:16, , 4F
09/21 05:16, 4F
→
09/21 13:30, , 5F
09/21 13:30, 5F