华农C语言程序设计实验 下载本文

内容发布更新时间 : 2024/5/23 21:24:30星期一 下面是文章的全部内容请认真阅读。

该文档最终解释权由Yang所有,未经允许不得转载

{ if(head==p1)head=p0; else p2->next=p0; p0->next=p1; }

else {p1->next=p0;p0->next=NULL;} }

return(head); }

[题目1099:链表的合并] 有结构体类型定义,

struct student

{ long num; /*学号*/ int score; /*成绩*/

struct student *next; /*指针*/ };

程序首先完成创建两个链表,要求补充完成实现将第二个链表合并到第一个链表未尾的函数。

struct student *merge(struct student *head, struct student *head2) {

struct student *p1; p1=head;

while(p1->next!=NULL)p1=p1->next; p1->next=head2; return(head); }

[题目1104:链表的倒序] 有结构体类型定义,

struct student

{ long num; /*学号*/ int score; /*成绩*/

struct student *next; /*指针*/ };

程序首先完成程序创建一个链表,要求补充完成实现将链表中各结点变为倒序排列的函数。

struct student *reverse(struct student *head) {

struct student *p1,*p2,*p3; p2=head;p3=head->next; do

{ p1=p2;p2=p3;p3=p2->next;p2->next=p1; }

while(p3!=NULL); head->next=NULL; return(p2); }

该文档最终解释权由Yang所有,未经允许不得转载

[题目1101:链表的排序] 有结构体类型定义,

struct student

{ long num; /*学号*/ int score; /*成绩*/

struct student *next; /*指针*/ };

程序首先完成程序创建一个链表,要求补充完成实现将链表中各结点按学号由小到大排序的函数。

struct student *sort(struct student *head) {

struct student *p1,*p2; p2=head;p1=head; p2=p2->next; p1->next=NULL; p1=p2;

while(p2->next!=NULL) {

p2=p2->next; p1->next=NULL;

head=insert(head,p1); p1=p2; }

head=insert(head,p1); return(head); }

请填空完成程序

(如 data1.in内容如下) Hello my Dear: Have a GooD Time!

(在屏幕上输出结果如下) hello my dear: have a good time! 程序如下,请填空, #include \main()

{ FILE *fp; char ch;

if((fp=fopen(\)= =NULL) return 0;

while((ch=fgetc(fp))!=EOF ) { if ('A'<=ch && ch<='Z') ch = ch + 32; putchar(ch) ;

该文档最终解释权由Yang所有,未经允许不得转载

}

fclose(fp); }

[题目1106:文本文件操作_字符写入] 参考程序:

#include \main()

{ FILE *fp;

char ch, ch1=' ', ch2=' ', ch3=' ';

if((fp=fopen(\return 1;

while((ch=getchar())!=EOF) { fputc(ch, fp);

ch1=ch2;ch2=ch3;ch3=ch;

if (ch1=='b'&&ch2=='y'&&ch3=='e') break; }

fclose(fp); }

[题目1107:文本文件操作_单词的排序] 参考程序:

#include \#include \main()

{ FILE *fp1,*fp2;

char str[1000][11],str1[11]; int n=0,i,j;

if((fp1=fopen(\return 0;

if((fp2=fopen(\return 0;

while(fscanf(fp1,\for(i=0;i

if(strcmp(str[i],str[j])>0) {

strcpy(str1,str[i]); strcpy(str[i],str[j]); strcpy(str[j],str1); }; }

for(i=0;i

fprintf(fp2,\

该文档最终解释权由Yang所有,未经允许不得转载

fclose(fp1); fclose(fp2); }__