| 查看: 1152 | 回复: 5 | ||
[求助]
求大侠帮忙看个程序
|
|
#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; } } 谁能帮忙看下这个程序的每个函数的时间复杂度空间复杂度是多少?还有最后个希尔排序算法每步的意思。谢谢啦 |
» 猜你喜欢
导师想让我从独立一作变成了共一第一
已经有8人回复
博士读完未来一定会好吗
已经有23人回复
到新单位后,换了新的研究方向,没有团队,持续积累2区以上论文,能申请到面上吗
已经有11人回复
读博
已经有4人回复
JMPT 期刊投稿流程
已经有4人回复
心脉受损
已经有5人回复
Springer期刊投稿求助
已经有4人回复
小论文投稿
已经有3人回复
申请2026年博士
已经有6人回复
» 本主题相关价值贴推荐,对您同样有帮助:
请大侠帮忙看一下这个包装和内含的是什么材料
已经有7人回复
大侠们帮忙看看这个教授的回复是潜在offer吗?
已经有17人回复
那位大侠,帮帮忙,求助一个二阶微分方程的解,谢谢!
已经有10人回复
求助大侠帮忙,有关matlab模拟数据
已经有29人回复
跪求各位大侠帮忙看看我得细胞怎么了~
已经有11人回复
求助:投稿了4个月,今天收到了一封奇怪的邮件。请大侠们帮忙分析一下
已经有16人回复
请各位大侠帮忙看一下我的液相色谱图究竟怎么了?
已经有13人回复
写了一个fortran90的小程序,编译通不过,请大侠帮忙
已经有59人回复
【求助】请大侠帮忙,看这个处理正确与否,指点迷津!
已经有4人回复
【求助】不知哪位大侠可以帮我把邮箱@以及其后缀名去掉,这些邮箱存在txt文本中。悬赏
已经有19人回复
【求助/交流】有做过单克隆抗体纯化的大侠帮忙给看一下
已经有5人回复
文章回来,请大侠帮忙看看
已经有8人回复
【求助】请大侠们帮忙看看这个是怎么把不适合做单晶衍射的化合物进行单晶分析的?
已经有6人回复

lt292
金虫 (正式写手)
Holy Shit
- 应助: 21 (小学生)
- 金币: 1256.1
- 散金: 50
- 红花: 3
- 帖子: 591
- 在线: 36.4小时
- 虫号: 668772
- 注册: 2008-12-05
- 性别: GG

2楼2011-12-30 16:19:25
lt292
金虫 (正式写手)
Holy Shit
- 应助: 21 (小学生)
- 金币: 1256.1
- 散金: 50
- 红花: 3
- 帖子: 591
- 在线: 36.4小时
- 虫号: 668772
- 注册: 2008-12-05
- 性别: GG

3楼2011-12-30 16:20:54

4楼2011-12-30 17:12:08
5楼2011-12-31 15:58:27
6楼2012-01-04 16:27:50













;
回复此楼