欢迎来到天天文库
浏览记录
ID:52108653
大小:31.50 KB
页数:3页
时间:2020-03-22
《数据结构全套配套课件C语言版李刚电子资源第2章.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第二章一、填空题1、n-i+12、1103、首结点尾结点直接后继直接前驱二、选择题1、B2、A3、C4、A三、应用题1、p=(LinkList*)malloc(sizeof(LinkList));2、p->next=q->next;free(q);3、(1)L=(21,19,0,34,30)(2)删除线性表中的所有负数4、(1)(2)将单链表中的数据域是偶数的结点向前移动,是奇数的结点向后移动。四、算法设计题1、#include"stdio.h"typedefstruct{intdata[10];intlength;}SeqList;main
2、(){SeqListlist;inti,t;for(i=0;i<10;i++)scanf("%d",&list.data[i]);list.length=10;for(i=0;i3、h"typedefstructnode{chardata;//结点的数据域,DataType为数据类型structnode*next;//结点的指针域}ListNode;ListNode*CreatList(){charch;ListNode*head=(ListNode*)malloc(sizeof(ListNode));//生成头结点ListNode*s,*r;//工作指针r=head;//尾指针初值也指向头结点while((ch=getchar())!=''){s=(ListNode*)malloc(sizeof(ListNode)4、);//生成新结点s->data=ch;//将读入的数据放入新结点的数据域中r->next=s;r=s;}r->next=NULL;//终端结点的指针域置空,或空表的头结点指针域置空returnhead;}ListNode*reverse(ListNode*head){ListNode*p,*s;//工作指针ListNode*head1=(ListNode*)malloc(sizeof(ListNode));//生成头结点head1->next=NULL;p=head->next;while(p!=NULL){s=(ListNode*)mal5、loc(sizeof(ListNode));//生成新结点s->data=p->data;s->next=head1->next;head1->next=s;p=p->next;}returnhead1;}voidprint(ListNode*head){ListNode*p;p=head->next;while(p!=NULL){printf("%c",p->data);p=p->next;}}main(){ListNode*head,*head1;head=CreatList();print(head);head1=reverse(hea6、d);print(head1);}
3、h"typedefstructnode{chardata;//结点的数据域,DataType为数据类型structnode*next;//结点的指针域}ListNode;ListNode*CreatList(){charch;ListNode*head=(ListNode*)malloc(sizeof(ListNode));//生成头结点ListNode*s,*r;//工作指针r=head;//尾指针初值也指向头结点while((ch=getchar())!=''){s=(ListNode*)malloc(sizeof(ListNode)
4、);//生成新结点s->data=ch;//将读入的数据放入新结点的数据域中r->next=s;r=s;}r->next=NULL;//终端结点的指针域置空,或空表的头结点指针域置空returnhead;}ListNode*reverse(ListNode*head){ListNode*p,*s;//工作指针ListNode*head1=(ListNode*)malloc(sizeof(ListNode));//生成头结点head1->next=NULL;p=head->next;while(p!=NULL){s=(ListNode*)mal
5、loc(sizeof(ListNode));//生成新结点s->data=p->data;s->next=head1->next;head1->next=s;p=p->next;}returnhead1;}voidprint(ListNode*head){ListNode*p;p=head->next;while(p!=NULL){printf("%c",p->data);p=p->next;}}main(){ListNode*head,*head1;head=CreatList();print(head);head1=reverse(hea
6、d);print(head1);}
此文档下载收益归作者所有