ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:17.20KB ,
资源ID:10459123      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10459123.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(卓越14U14716彭佳伟第十九周.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

卓越14U14716彭佳伟第十九周.docx

1、卓越14U14716彭佳伟第十九周12.5 编写一个测试一个字符串是否为回文的递归函数,是回文,返回1;不是回文,返回0。void judge (char * str, int n) int start = strlen(str) - n; int end = n-1; if (strstart = strend) if (end - start 1) judge(str, n-1); else printf(1n); else printf(0n); 13.1 编写带哨兵的直接插入排序算法,将哨兵放在a0中,被排序的纪录放在a1an-1中。#include #ifndef MAX#defin

2、e MAX 8#endifint main(int argc, char const *argv) int aMAX = 0, 1, 2, 5, 3 ,6 ,3, -2; int j,i; int tmp; for (i = 2; i MAX; +i) a0 = ai; for (j = i-1; a0 aj; -j) aj+1 = aj; aj+1 = a0; for (i = 1; i 3) split = Partition(a, left, right); QuickSort(a, left, split-1); QuickSort(a, split+1, right); else i

3、f(right - left 0) InsertSort(a, left, right); int Partition(int a, int left, int right) int split = (left + right)/2; swap(a, left, split); int i = left; int j = right+1; while (1) while(a+i = aleft & i aleft); if(i = j) break; swap(a, i, j); swap(a, j, left); return j;void swap(int a, int i, int j)

4、 int temp; temp = ai; ai = aj; aj = temp;void InsertSort(int a, int left, int right) int i; int j; int temp; for (i = left+1; i = 0 & aj temp; j-) aj+1 = aj; aj+1 = temp; 14.4 输入一行长度无限制超长字符串,用一个先进先出且每个节点接受一个输入字符的单向链表接受这个字符串。再完成下列任务:(1)遍历输出链表中的所有字符;(2)将该超长字符串无冗余地存放到一个通过动态存储分配创建地字符数组中,并且通过puts函数或print

5、f函数输出该超长字符串。#include #include typedef struct String String;struct String char ch; String *next;void SaveSring(String * head);void PrintString(String *head);void SaveToArray(String *head);int main(void) String *head = NULL; printf(Please input a stringn); SaveSring(&head); PrintString(head); SaveToAr

6、ray(head); return 0;void SaveSring(String * head) String *current = NULL; String *previous = NULL; while( 1 ) current = (String*)malloc(sizeof(String); if (*head = NULL) *head = current; if (previous != NULL) previous-next = current; previous = current; current-next = NULL; scanf(%c, ¤t-ch); i

7、f (current-ch = n) current-ch = 0; current-next = NULL; break; void PrintString(String *head) while (head != NULL) printf(%c, head-ch); head = head-next; printf(n);void SaveToArray(String *head) int cnt; String *temp = head; for(cnt = 1; temp-next != NULL; cnt+) temp = temp-next; char stringcnt; for

8、 (int i = 0; i ch; head = head-next; puts(string);14.5 用后进先出单向链表重做第14.3。#include #include #include #include typedef struct Student Student;struct Student int number; char name10; float subject1; float subject2; float subject3; float average; Student *next;void Input(Student *head);void Output(Studen

9、t *head);void ChangeInfo(Student *head);void Sort(Student *head);int main(void) Student *head = NULL; int n; int flag = 1; while (flag = 1) printf(Please input the number of options :n); printf(1 : Input Informationt 2 : Change Informationn); printf(3 : Output Informationt 4 : Sort Informationn); pr

10、intf(5 : Quitn); scanf( %d, &n); switch (n) case 1: Input(&head); break; case 2: ChangeInfo(head); break; case 3: Output(head); break; case 4: Sort(head); break; case 5: flag = 0; break; default: printf(Illegal Input! Please input again.); break; printf(nn); return 0;void Input(Student *head) / 采用的是

11、后进先出的单向链表 char answer = y; while (answer = y) Student *current = NULL; current = (Student*)malloc(sizeof(Student); current-next = *head; *head = current; printf(Please input the students number : ); scanf( %d, ¤t-number); printf(Please input the students name : ); scanf( %s, current-name); pri

12、ntf(Please input the score of subject1 : ); scanf( %f, ¤t-subject1); printf(Please input the score of subject2 : ); scanf( %f, ¤t-subject2); printf(Please input the score of subject3 : ); scanf( %f, ¤t-subject3); current-average = (current-subject1 + current-subject2 + current-subj

13、ect3)/3; printf(Do you want to input the infomation of another student? (Y/N) ); scanf( %c, &answer); answer = tolower(answer); void Output(Student *head) if (head = NULL) printf(You have not input any information!); else printf(nnttThe Infomation Of Studentsn); do printf(name:%stt, head-name); prin

14、tf(number:%dtt, head-number); printf(average:%.2fn, head-average); printf(subject1:%.2ft, head-subject1); printf(subject2:%.2ft, head-subject2); printf(subject3:%.2fnn, head-subject3); head = head-next; while (head != NULL); void ChangeInfo(Student *head) if (head = NULL) printf(You have not input a

15、ny information!); else Student *current = head; char name10; int flag = 0; int n; printf(Please input the students name : ); scanf(%s, name); while (current-next != NULL) if (strcmp(name, current-name) != 0) current = current-next; else flag = 1; printf(Please input the number of options :n); printf

16、(1 : subject1t2 : subject2t 3 : subject3t 4 : namet 5 : numbern); scanf(%d, &n); switch (n) case 1: printf(Please input the score of subject1 : ); scanf( %f, ¤t-subject1); break; case 2: printf(Please input the score of subject2 : ); scanf( %f, ¤t-subject2); break; case 3: printf(Please

17、input the score of subject3 : ); scanf( %f, ¤t-subject3); break; case 4: printf(Please input the students name : ); scanf( %s, current-name); break; case 5: printf(Please input the students number : ); scanf( %d, ¤t-number); default: break; if (n average = (current-subject1 + current-sub

18、ject2 + current-subject3)/3; break; void Sort(Student *head) /采用的是冒泡排序 /交换的是数据域,不是指针 if (head = NULL) printf(You have not input any information!); else Student temp; while (head-next != NULL) Student *current = head; while (current-next != NULL) if (current-average next-average) temp = *current; temp.next = current-next-next; current-next-next = current-next; *current = *current-next; *current-next = temp; current = current-next; head = head-next;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1