DS上機考(counting-sort正確性存疑
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
{
int number,n=0,i=0,j,k=0,d;
int A[150],C[1000],B[150],K;//A原始陣列,B排序後陣列,C計算每個數字個數的陣列
printf("輸入想要的個數\n");
scanf("%d",&n);//個數
printf("range\n");
scanf("%d",&K);//範圍
srand(time(0));
printf("A:\n");
for(;n>0;n--)//印A陣列
{
number=rand()%K;//取亂數
A[i]=number;i++;k=i;//置入A陣列,並計算元素
printf("%d\n",number);//印出
}
for(j=0;j<1000;j++)//歸零C陣列<br />
C[j]=0;
for(i=0;i<k;i++)<br />
{
C[A[i]-1]++;//計算每種元素的個數
}
k=0;
for(j=0;j<1000;j++)<br />
{
for(i=0;i<C[j];i++)<br />
{
//printf("\n\n%d(%d)",j+1,C[j]);
B[k]=j+1;k++;d=k;//將排序後結果放入B陣列
}
}
printf("\nB:\n");//印出B
for(i=0;i<k;i++)<br />
{
printf("%d\n",B[i]);
}
}
Today's Visitors: 0 Total Visitors: 32


Sealed (Jun 21)
1樓
1樓搶頭香
完全看不懂妳在寫啥
大三下要繼續加油喔!
謝謝你的賀卡啦XD
2樓
2樓頸推
最資深的專業情趣團隊,把關嚴選給你最性福的情趣用品
感謝數年來網友給我們的支持與肯定
客戶最性福的滿意笑容,是我們用心服務的最大動力
▉ ▉大波霸情趣玩具~品質服務多元創新▉ ▉
▉◎█快上 http://www.dapoba.com.tw 歡迎免費加盟!
3樓
3樓坐沙發
最資深的專業情趣團隊,把關嚴選給你最性福的情趣用品
感謝數年來網友給我們的支持與肯定
客戶最性福的滿意笑容,是我們用心服務的最大動力
■ ■大波霸情趣網~品質服務多元創新■ ■
■◤△快上 http://www.dapoba.com.tw 歡迎免費加盟!