#include <iostream.h>
#include <stdlib.h>
#include "LinList2.h"
#include <math.h>
LinList<int> myList;
int i,n,temp;
char a;
void myListCout()//输出
{
for(i = 0; i < myList.ListSize(); i++)
{
temp = myList.GetData(i);
cout << temp << " ";
}
cout<<endl;
}
void myListInsert()//升序插入新数
{
while(1)
{
cout<<"是否还需要输入新的数,Y代表是,N代表否"<<endl;
cin>>a;
if(a=='N'||a=='n') break;
cout<<"请输入新数"<<endl;
cin>>n;
myList.OrderInsert(n);
cout<<"下面升序输出数组"<<endl;
myListCout();
}
}
void myListInsert2()//逆序插入新数
{
while(1)
{
char b;
cout<<"是否还需要输入新的数,Y代表是,N代表否"<<endl;
cin>>a;
if(a=='N'||a=='n') break;
for(i=0;a!='N'&&a!='n';i++)
{
if(i % 2 == 0)
{
cout<<"因为当前数组为逆序,必须转化为升序才可以插入,是否要转换成升序,Y代表是,N代表否";
cin>>b;
if(b=='N'||b=='n') break;
myList.Converse();
cout<<"请输入新数"<<endl;
cin>>n;
myList.OrderInsert(n);
cout<<"下面升序输出数组"<<endl;
myListCout();
}
myListInsert(); //逆序之后为升序插入
}
}
}
void main(void)
{
cout<<"请输入数组,以-1结束输入"<<endl;
for(i=0;n!= -1;i++)
{
cin>>n;
if(n==-1) break;
myList.OrderInsert(n);
}
cout<<"下面升序输出数组"<<endl;
myListCout();
myListInsert();
cout<<"下面逆序输出数组"<<endl;
myList.Converse();
myListCout();
myListInsert2();
system ("pause");
}
用带表头的链表存放输入的数据,每读入一个数,按升序顺序插入到链表中
5星 · 超过95%的资源 需积分: 10 171 浏览量
2010-12-15
19:39:22
上传
评论 6
收藏 43KB RAR 举报
tamakiramimy
- 粉丝: 0
- 资源: 9
最新资源
- 花数据集+数据集汇总+标签txt+数据集汇总代码+迁移学习最佳模型+全部迭代最佳模型
- 20240329224412.zip
- switch.docx `switch`语句是C++中的一种流程控制语句,通常用于根据表达式的值选择执行不同的代码块 下面是`
- python绘制直方图-02-进程之间不共享全局变量.ev4.rar
- python绘制直方图-01-第三天知识点回顾.ev4.rar
- 01背包问题动态规划.docx
- 表达式求值.docx表达式求值涉及许多不同的情况和方法,具体取决于表达式的形式和要求的精度 下面是一个简单的例子
- python绘制直方图-08-软件的卸载.ev4.rar
- tcp和udp的区别.docx
- 斐波那契数列c.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈