C++教材练习题参考答案(3)
for(p=s;p<s+3;p++)
{
cout<<p->num ;
cout<<'\t'<<p->ave;
cout<<'\t'<<p->CPPmid ;
cout<<'\t'<<p->CPPend;
cout<<endl;
}
}
中国铁道建设出版
4.[程序如下]
struct link
{
int data;
link*next;
};
int sum(link *head)
{
} link *p; int s=0; p=head->next; while(p) { } s+=p->data; p=p->next; return s;
5.[程序如下]
#include<iostream.h>
struct node
{
int data;
node *next;
};
node *create( )
{
node *head ; //头指针
node *p , *pend ;
int a;
cout<<"请输入数据(为零表示结束输入):" ;
cin>>a;
head=0 ;
while(a!=0)
{
p=new node ;
p->data=a ;
if(head==0)
{
head=p ;
pend=p ;
中国铁道建设出版
else { pend->next=p ; pend=p ; }
cout<<"请输入数据(为零表示结束输入):" ;
cin>>a;
}
if(head) pend->next=0 ;
return head ;
}
node * invert(node *head)
{
node *p,*q;
p=head->next;
if(p!=NULL)
{
head->next=NULL;
do
{
q=p->next;
p->next=head;
head=p;
p=q;;
}while(p!=NULL);
}
return head;
}
void print(node *head )
{
if(head==0) { cout<<" 链表为空!\n" ; return ; }
node *p=head ;
cout<<"链表上各个结点的值为:\n";
while(p!=0)
{
cout <<p-> data<<'\t' ;
p=p->next ;
}
}
void release(node *head )
中国铁道建设出版
if(head==0) { cout<<" 链表为空!\n" ; return ; }
node *p ;
while( head )
{
}
}
void main( )
{
node *head;
head=create( );
print(head);
head=invert(head);
cout<<"\n逆置后";
print(head);
release(head);
}
6.[程序如下]
#include <iostream.h>
struct Node
{
int x; //围成一圈时,人的序号
Node *next;
};
Node * DelNode(Node *head, int m) //依次输出环形链表中凡报到m者的序号 { Node *p;
int count; if(head==NULL) return head;;
while( head != head->next) //直到链表上只有一个结点为止
{
count=0; while(count < m-2) { count++; head = head->next; p=head; head=head->next ; delete p; cout<<"\n结点空间释放完毕!"; } p=head->next; //删除p所指向的结点 head->next = p->next;
相关推荐:
- [小学教育]四年级综合实践活动课《衣物的洗涤》教
- [小学教育]2014半年工作总结怎么写
- [小学教育]20世纪外国文学专题综合试题及答案
- [小学教育]TS_1循环使用催化丙烯环氧化反应研究
- [小学教育]最实用的考勤签到表(上下班签到表)
- [小学教育]气候与生态建筑——以新疆民居为例
- [小学教育]二人以上股东有限责任公司章程参考样本
- [小学教育]2014届第一轮复习资料4.1,3美好生活的
- [小学教育]土方开挖、降水方案
- [小学教育]手绘儿童绘本《秋天的图画》(蜡笔)
- [小学教育]2002级硕士研究生卫生统计学考试试题
- [小学教育]环保装备重点发展目录
- [小学教育]金蝶K3合并报表培训教材
- [小学教育]岩浆岩试题及参考答案
- [小学教育]知之深爱之切学习心得
- [小学教育]第十二章 蛋白质的生物合成
- [小学教育]Chapter 2-3 Solid structure and basi
- [小学教育]市政道路雨季专项施工方案
- [小学教育]中国海洋大学2012-2013学年第二学期天
- [小学教育]教育心理学第3章-学习迁移
- 浅谈深化国企改革中加强党管企业
- 2006年中国病理生理学会学术活动安排
- 设计投标工作大纲
- 基于ARP的网络攻击与防御
- 2016届湖北省七市(州)教科研协作体高三
- Google_学术搜索及其检索技巧
- 2019-2020学年七年级地理下册6.3美洲教
- 城市道路可研报告
- 【名师指津】2012高考英语 写作基础技
- 6级知识点培训北京师范大学《幼儿智趣
- 注册会计师会计知识点:金融资产
- 新安装 500 kV 变压器介损分析与判断
- PS2模拟器PCSX2设置及使用教程.
- 医院药事管理与药剂科管理组织机构
- {PPT背景素材}丹巴的醉人美景,免费,一
- NAS网络存储应用解决方案
- 青海省西宁市六年级上学期数学期末考试
- 测量管理体系手册依据ISO10012:2003
- 洞子小学培养骨干教师工作计划
- 浅谈《牛津初中英语》的教材特点及教学




