如何在图中第三列用if函数中并列条件表示第一列和第二列的排序结果,先主次要关键字排序,然后怎么在第三列用if函数中并列条件表示

c++程序设计第3版谭浩强课后答案
当前位置: >>
15:22:52&&分类: c++程序设计第三版谭浩强课后答案&&参与: 人
C++编程:将以上4个函数组成一个程序,由主程序先后调出这些函数,实现链表的建立、输出、删除和插入,在主程序中指定需要删除和插入的结点。
以下是此题的【c++源代码】
#include &iostream&
#define NULL 0&&&&
struct student
&student *
int main()
{ student *creat(void);
& student *del(student *,long);&
& student *insert(student *,student *);
& void print(student *);
& student *head,*
& long del_
& cout&&"input records:"&&
& head=creat();&&&&&&&&&&&&&&&&&&&&&&& //返回头指针
& print(head);&&&&&&&&&&&&&&&&&&&&&&&&& //输出全部结点
& cout&&endl&&"input the deleted number:";
& cin&&del_&&&&&&&&&&&&&&&&&&&&&&& //输入要删除的学号
& while(del_num!=0)
& {head=del(head,del_num);&&&&&&&&&&&&& //删除后链表的头地址
&& print(head);&&&&&&&&&&&&&&&&&&&&&&&& //输出全部结点
&& cout&&"input the deleted number:";
&& cin&&del_
& cout&&endl&&"input the inserted record:";& //输入要插入的结点
& stu=&&&&&&&&&&&&&&&&&&&&& //开辟一个新结点
& cin&&stu-&num&&stu-&
& while(stu-&num!=0)
& {head=insert(head,stu);&&&&&&&&&&&&& //返回地址
&& print(head);&&&&&&&&&&&&&&&&&&&&&&&& //输出全部结点
&& cout&&endl&&"input the inserted record:";& //输入要插入的结点
&& cin&&stu-&num&&stu-&
& return 0;
student *creat(void)&&&&&& //建立链表的函数
{student *
&student *p1,*p2;
&p1=p2=&&&&&& //开辟一个新单元,并使p1,p2指向它
&cin&&p1-&num&&p1-&
&head=NULL;
&while(p1-&num!=0)
&if(n==1) head=p1;
&else p2-&next=p1;
&cin&&p1-&num&&p1-&
p2-&next=NULL;
return(head);
student *del(student *head,long num)&& //删除结点的函数
{student *p1,*p2;
&if (head==NULL)&&&&&&&&&&&&&&&&&&& //是空表
&{cout&&"list null!"&& return(head);}
&p1=&&&&&&&&&&&&&&&&&&&&&&&&& //使p1指向第一个结点
&while(num!=p1-&num && p1-&next!=NULL) //p1指向的不是所要找的结点且后面还有结点
&{p2=p1; p1=p1-&}&&&&&&&&&&&&&&&& //p1后移一个结点
&if(num==p1-&num)&&&&&&&&&&&&&&&&&&&&&&& //找到了
&{if(p1==head) head=p1-&&& //若p1指向的是首结点,把第二个结点地址赋予head
& else p2-&next=p1-&&&& //否则将下一结点地址赋给前一结点地址
& cout&&"delete:"&&num&&
&else cout&&"cannot find "&&&&&& //找不到该结点
&return(head);
student *insert(student *head,student *stud)& //插入结点的函数
{student *p0,*p1,*p2;
&p1=&&&&&&&&&&&&&&&&&&&&&&&&& //使p1指向第一个结点
&p0=&&&&&&&&&&&&&&&&&&&&&&&&& //指向要插入的结点
&if(head==NULL)&&&&&&&&&&&&&&&&&&& //原来的链表是空表
&{head=p0;p0-&next=NULL;}&&&&&&&&& //使p0指向的结点作为头结点
&{while((p0-&num&p1-&num) && (p1-&next!=NULL))
&{p2=p1;&&&&&&&&&&&&&&&&&&&&&& //使p2指向刚才p1指向的结点
& p1=p1-&}&&&&&&&&&&&&&&& //p1后移一个结点
& if(p0-&num&=p1-&num)
& {if(head==p1) head=p0;&&&&&&& //插到原来第一个结点之前
&& else p2-&next=p0;&&&&&&&&&&& //插到p2指向的结点之后
&& p0-&next=p1;}
& {p1-&next=p0; p0-&next=NULL;}}& //插到最后的结点之后
&& n=n+1;&&&&&&&&&&&&&&&&&&&&&&&& //结点数加1
&& return (head);
&&&&&&&&&&&&&&
void print(student *head)&&&&&&&& //输出链表的函数
&{student *p;
& cout&&"Now,These "&&n&&" records are:"&&
& if(head!=NULL)
&&& {cout&&p-&num&&"& "&&p-&score&&
&&&& p=p-&
&}while(p!=NULL);
本文链接:
本站文章搜索:
相关文章 18:14:26 15:14:37 15:10:17 15:1:31 15:0:26 14:35:52北邮数据结构实验 第三次实验 排序_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
北邮数据结构实验 第三次实验 排序
上传于|0|0|文档简介
&&北邮数据结构实验
排序 2015年最新版,带源代码
阅读已结束,如果下载本文需要使用1下载券
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩20页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢

我要回帖

更多关于 zemax点列图优化函数 的文章

 

随机推荐