| 5 | 1/1 | 返回列表 |
| 查看: 1251 | 回復: 5 | ||
| 當前只顯示滿足指定條件的回帖,點擊這里查看本話題的所有回帖 | ||
xiaolei@金蟲 (小有名氣)
|
[求助]
求大俠幫忙看個程序
|
|
|
#include #include typedef struct node { char name[8]; int num; int score; int tax; }Node; // 候選人結構 void shellSort( Node **, int ); int main(void) { int n = 0; Node * pArray[9];//指針數(shù)組,長度9 int count = 0; //int status = 1; int vote = -1; printf("Input the number of the candidates(1-9):\n" ;scanf("%d", &n); while(getchar()!='\n') { ; } while (n>9 || n<1) { if (n>9) { printf("No, there cannot be so many candidates. Retry.\n" ;} else { printf("No candidates? It cannot be! Retry!\n" ;} scanf("%d", &n); while(getchar()!='\n') { ; } } for (count=0; count pArray[count] = (Node *)malloc(sizeof(Node)); pArray[count]->num = count+1; pArray[count]->tax = 0; pArray[count]->score = 0; printf("Input No.%d candidate's name:\n", count+1); gets(pArray[count]->name); } while (vote) { printf("Now, let us vote:\n*************\n" ;for (count=0; count printf("%d. %s\n", count+1, pArray[count]->name); } printf("0.quit\n*************\n" ;scanf("%d", &vote); while(getchar()!='\n') { ; } while (vote<0 || vote>n) { printf("No joke, thank you. Revote.\n" ;scanf("%d", &vote); while(getchar()!='\n') { ; } } if (vote>0&&vote<=n) { pArray[vote-1]->score++; } } printf("Finish voting. Let's find the winner......\n\n" ;shellSort( pArray, n ); for (count=0; count pArray[count]->tax=count+1; printf("%d. %s %d votes.\n", count+1, pArray[count]->name, pArray[count]->score); } for(count=0; count free(pArray[count]); pArray[count] = NULL; } return 0; } void shellSort( Node *p[], int len ) { const int Length = len; int i = 0; int j = 0; int gap = 0; Node *temp = NULL; gap = Length/2; while (gap>0) { for (i=gap; i j = i - gap; temp = *(p+i); while ( (j>=0) && (p[j]->score < temp->score) ) { *(p+j+gap) = *(p+j); j = j - gap; } *(p+j+gap) = temp; } gap /= 2; } } 誰能幫忙看下這個程序的每個函數(shù)的時間復雜度空間復雜度是多少?還有最后個希爾排序算法每步的意思。謝謝啦 |

金蟲 (正式寫手)
Holy Shit

金蟲 (正式寫手)
Holy Shit

金蟲 (小有名氣)

| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 330分求調劑 +3 | qzenlc 2026-03-29 | 3/150 |
|
|---|---|---|---|---|
|
[考研] 學碩274求調劑 +9 | Li李魚 2026-03-26 | 9/450 |
|
|
[考研] 求調劑一志愿海大,0703化學學碩304分,有大創(chuàng)項目,四級已過 +7 | 幸運哩哩 2026-03-22 | 11/550 |
|
|
[考研] 322求調劑 +5 | 舊吢 2026-03-24 | 5/250 |
|
|
[考研] 0703一志愿9,初試成績:338,四六級已過,有科研經(jīng)歷,求調劑! +4 | Zuhui0306 2026-03-25 | 4/200 |
|
|
[考研] 291求調劑 +15 | hhhhxn.. 2026-03-23 | 21/1050 |
|
|
[考研] 277跪求調劑 +5 | 1915668 2026-03-27 | 9/450 |
|
|
[考研] 330一志愿中國海洋大學 化學工程 085602 有讀博意愿 求調劑 +3 | wywy.. 2026-03-27 | 4/200 |
|
|
[考研] 085600,材料與化工321分調劑 +4 | 大饞小子 2026-03-27 | 6/300 |
|
|
[考研] 考研調劑 +10 | 呼呼?~+123456 2026-03-24 | 10/500 |
|
|
[論文投稿] Journal of Mechanical Science and Technology +3 | Russ_ss 2026-03-25 | 5/250 |
|
|
[考研] 一志愿北化求調劑 +3 | Jsman 2026-03-22 | 3/150 |
|
|
[考研] 【雙一流院校新能源、環(huán)境材料,材料加工與模擬招收大量調劑】 +4 | Higraduate 2026-03-22 | 8/400 |
|
|
[考研] 0703化學求調劑 +3 | 丹青奶蓋 2026-03-26 | 5/250 |
|
|
[考研] 機械學碩310分,數(shù)一英一,一志愿211本科雙非找調劑信息 +3 | @357 2026-03-25 | 3/150 |
|
|
[考研] 生物技術與工程 +3 | 1294608413 2026-03-25 | 4/200 |
|
|
[考研] 347求調劑 +4 | L when 2026-03-25 | 4/200 |
|
|
[考研] 化工專碩求調劑 +3 | question挽風 2026-03-24 | 3/150 |
|
|
[考研] 求調劑一志愿武漢理工大學材料工程(085601) +5 | WW.' 2026-03-23 | 7/350 |
|
|
[考研] 361求調劑 +3 | Glack 2026-03-22 | 3/150 |
|