教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 学前教育 >

c语言经典笔试题(非常全)(14)

来源:网络收集 时间:2026-07-11
导读: if( a[j] } } 链表问题汇总 178写一函数creat, 用来建立一个动态链表,各结点数据由键盘输入。 struct student { }; student *creat (void) { } 179,写一print函数,将链表中的各数据遍历输出 void print(student

if( a[j]

} }

链表问题汇总

178写一函数creat, 用来建立一个动态链表,各结点数据由键盘输入。 struct student { };

student *creat (void) { }

179,写一print函数,将链表中的各数据遍历输出 void print(student *head ) {

student *p; student *head;

student *p1=null,*p2=null; int n=0;

p1=p2=new student; cin>>p1->num>>p1->score; head=null; while(p1->num !=0) { }

p2->next =NULL; return (head);

n=n+1;

if(1==n) head=p1; else p2->next=p1; p2=p1;

p1= new student;

cin>>p1->mum>>p1->score; long num; float score; stuent *next;

}

cout<<\p=head; if(head!=NULL) do {

cout<num<<\p=p->next;

}while(p!=NULL)

180.写一del函数,用来删除动态链表中,指定的结点数据 void *del(student *head, long num) { }

181 写一函数insert,用来向动态链表插入一结点 Student *insert(student *head, student *stud) {

student *p0 ,*p1, *p2; p1=head; p0=stud; if(head == NULL) {

head=p0; student *p1,*p2; if(head==NULL) {return (head);} p1=head;

while(num!=p1->num && p1->next !=NULL) { }

if(num == p1->num) { } else

cout<<\return(head);

if(p1==head) else

p2->next=p1->next;

cout<<\n=n-1;

head=p1->next;

p2=p1; p1=p1->next;

}

} else { }

p0->next=NULL;

while((p0->num >p1->num) && (p1->next!=NULL) ) { }

if(p0->num <= p1->num) { } else { }

p1->next=p0; p0->next=NULL;

if(head ==p1) else

p2->next=p0; p0->next=p1;

head=p0; p2=p1; p1=p1->next;

n=n+1; return(head);

182 链表题:一个链表的结点结构 struct Node { int data ; Node *next ; };

typedef struct Node Node ;

(1)已知链表的头结点head,写一个函数把这个链表逆序 ( Intel)

Node * ReverseList(Node *head) //链表逆序 {

if ( head == NULL || head->next == NULL ) return head; Node *p1 = head ; Node *p2 = p1->next ;

Node *p3 = p2->next ; p1->next = NULL ; while ( p3 != NULL ) {

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

p2->next = p1 ; head = p2 ; return head ; }

(2)已知两个链表head1 和head2 各自有序,请把它们合并成一个链表依然有序。(保留所有结点,即便大小相同)

Node * Merge(Node *head1 , Node *head2) {

if ( head1 == NULL) return head2 ; if ( head2 == NULL) return head1 ; Node *head = NULL ; Node *p1 = NULL; Node *p2 = NULL;

if ( head1->data < head2->data ) {

head = head1 ; p1 = head1->next; p2 = head2 ; } else {

head = head2 ; p2 = head2->next ; p1 = head1 ; }

Node *pcurrent = head ;

while ( p1 != NULL && p2 != NULL) {

if ( p1->data <= p2->data ) {

pcurrent->next = p1 ; pcurrent = p1 ; p1 = p1->next ;

} else {

pcurrent->next = p2 ; pcurrent = p2 ; p2 = p2->next ; } }

if ( p1 != NULL ) pcurrent->next = p1 ; if ( p2 != NULL ) pcurrent->next = p2 ; return head ; }

(3)已知两个链表head1 和head2 各自有序,请把它们合并成一个链表依然有序,这次要求用递归方法进行。 (Autodesk) 答案:

Node * MergeRecursive(Node *head1 , Node *head2) {

if ( head1 == NULL ) return head2 ; if ( head2 == NULL) return head1 ; Node *head = NULL ; if ( head1->data < head2->data ) {

head = head1 ;

head->next = MergeRecursive(head1->next,head2); } else {

head = head2 ;

head->next = MergeRecursive(head1,head2->next); }

return head ; }

183.利用链表实现将两个有序队列A和B合并到有序队列H中,不准增加其他空间。 请提供全一点的程序

以升序为例:

while(a != NULL && b!= NULL) {

if (a->data < b->data)

…… 此处隐藏:764字,全部文档内容请下载后查看。喜欢就下载吧 ……
c语言经典笔试题(非常全)(14).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/592983.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)