| 6 | 1/1 | 返回列表 |
| 查看: 1249 | 回復: 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];//指針數組,長度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; } } 誰能幫忙看下這個程序的每個函數的時間復雜度空間復雜度是多少?還有最后個希爾排序算法每步的意思。謝謝啦 |

金蟲 (正式寫手)
Holy Shit

金蟲 (正式寫手)
Holy Shit

金蟲 (小有名氣)

| 6 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 復試調劑 +3 | raojunqi0129 2026-03-28 | 3/150 |
|
|---|---|---|---|---|
|
[考研] 本科雙非材料,跨考一志愿華電085801電氣,283求調劑,任何專業(yè)都可以 +5 | 芝士雪baoo 2026-03-28 | 6/300 |
|
|
[考研] 070305高分子化學與物理 304分求調劑 +4 | c297914 2026-03-28 | 4/200 |
|
|
[考研] 085600 286分 材料求調劑 +7 | 麻辣魷魚 2026-03-27 | 8/400 |
|
|
[考研] 286求調劑 +12 | PolarBear11 2026-03-26 | 12/600 |
|
|
[考研] 材料求調劑 一志愿哈工大總分298分,前三科223分 +5 | dongfang59 2026-03-27 | 5/250 |
|
|
[考研] 334求調劑 +3 | 雨清天晴 2026-03-21 | 3/150 |
|
|
[考研] 0703化學338求調劑! +6 | Zuhui0306 2026-03-26 | 7/350 |
|
|
[考研] 336材料求調劑 +7 | 陳瀅瑩 2026-03-26 | 9/450 |
|
|
[考研] 321求調劑 +6 | Ymlll 2026-03-24 | 6/300 |
|
|
[考研] 325求調劑 +3 | Aoyijiang 2026-03-23 | 3/150 |
|
|
[考研] 化學工程085602 305分求調劑 +17 | RichLi_ 2026-03-25 | 17/850 |
|
|
[考研]
|
平樂樂樂 2026-03-26 | 4/200 |
|
|
[考研] 352求調劑 +4 | 大米飯! 2026-03-22 | 4/200 |
|
|
[考研] 【2026考研調劑】制藥工程 284分 求相關專業(yè)調劑名額 +4 | 袁奐奐 2026-03-25 | 8/400 |
|
|
[考研] 一志愿武理085500機械專業(yè)總分300求調劑 +3 | an10101 2026-03-24 | 7/350 |
|
|
[考研] 344求調劑 +3 | desto 2026-03-24 | 3/150 |
|
|
[考博] 26申博自薦 +3 | whh869393 2026-03-24 | 3/150 |
|
|
[考研] 269求調劑 +4 | 我想讀研11 2026-03-23 | 4/200 |
|
|
[考研] 一志愿北京化工大學070300 學碩336求調劑 +5 | vv迷 2026-03-21 | 8/400 |
|