简单的数字顺序表游戏
来源:互联网 发布:nginx 快速配置 编辑:程序博客网 时间:2024/06/10 08:00
#include<iostream>
#include<stdlib.h>
using namespace std;
typedef int ElemType;
const int Maxsize=100;
struct List
{
int size;
ElemType list[Maxsize];
};
void InitList(List &L)//初始化
{
L.size=0;
}
void ClearList(List &L)//清空
{
L.size=0;
}
int LenthList(List &L)//得到线性表的长度
{
return L.size;
}
bool EmptyList(List &L)//判断线性表是否为空
{
return L.size==0;
}
ElemType GetList(List &L,int pos)//找出给定序号pos的元素
{
if(pos<1 || pos>L.size)
{
cout << " pos is out range! " << endl;
exit(1);
}
return L.list[pos-1];
}
void TraverseList(List &L)//遍历线性表
{
for(int i=0; i<L.size; i++)
}
bool FindList(List &L, ElemType& item)//找出给定值
{
for(int j=0; j<L.size;j++)
if(L.list[j] == item)
{
item = L.list[j];
return true;
}
return false;
}
bool UpdateList(List &L, const ElemType& item)//更新线性表的值
{
for(int k=0; k<L.size; k++)
if(L.list[k] == item)
{
L.list[k] = item;
return true;
}
return false;
}
bool InsertList(List &L, ElemType item, int pos)//按指定条件插入元素
{
if(pos<-1 || pos>L.size+1)
{
cout << "pos值无效!" << endl;
return false;
}
if(pos==0)
{
for(int l=0; l<L.size; l++)
if(item<L.list[l]) break;
pos=l+1;
}
L.size++;
return true;
}
bool DeleteList(List &L, ElemType& item, int pos)//按指定条件删除元素
{
if(L.size==0)
{
cout << "线性表为空,删除无效!" << endl;
return false;
{
cout << "pos值无效!" << endl;
return false;
{
{
L.list[r-1]=L.list[r];
}
L.size--;
return true;
}
void SortList(List &L)//排序
{
ElemType x;
for(int p=1; p<L.size; p++)
{
L.list[q+1]=x;
}
}
int main()
{
int a[12]={3,4,7,9,13,16,17,34,23,12,2,49};
List t;
TraverseList(t);
cout << " 欢迎来到×××的数字顺序表游戏! " << endl;
cout << " 请选择:" << endl;
cout << " 1.新建数字顺序表 " << endl;
cout << " 2.查找某数是否在表中 " << endl;
cout << " 3.插入一个数字到表中 " << endl;
cout << " 4.删除表中某数" << endl;
cout << " 5.给数字顺序表排序 " << endl;
cout << " 6.屏幕输出整个表 " << endl;
cout << " 7.不想玩了,拜拜! " << endl;
int e=0, g=0;
int z=0, h=0 ;
int f=0, y=0;
cin >> b;
for(int b1=0; ;b++)
{
switch(b)
{
case 1:
cout << "请输入线性表的长度n(n>0且n<100):" << endl;
List t1;
InitList(t1);
for(; e<b; e++)
cin >> d[e];
for(; f<b; f++)
InsertList(t1, d[f],f);
TraverseList(t1);
cout << "输入待查找的元素值:";
cin >> g;
if(FindList(t,g))
cout << "查找成功!" << endl;
else cout << "查找失败!" << endl;
cout << "按值插入,输入待插入元素的值:";
cin >> h;
if(InsertList(t,h,0)) cout << "插入成功!" << endl;
else cout << "插入失败!" << endl;
TraverseList(t);
cout << "输入待删除元素的值:" << endl;
cin >> y;
if(DeleteList(t,y,0)) cout << "删除成功!" << endl;
else cout << "删除失败!" << endl;
TraverseList(t);
cout << "下面将给数字表排序:";
SortList(t);
TraverseList(t);
cout << "下面将输出整个表:" << endl;
TraverseList(t);
cout << " 不想玩了,拜拜! " << endl;
cout << " Error " << endl;
break;
}
if(b==7) exit(1);
cout << " 欢迎来到×××的数字顺序表游戏! " << endl;
cout << " 请选择:" << endl;
cout << " 1.新建数字顺序表 " << endl;
cout << " 2.查找某数是否在表中 " << endl;
cout << " 3.插入一个数字到表中 " << endl;
cout << " 4.删除表中某数" << endl;
cout << " 5.给数字顺序表排序 " << endl;
cout << " 6.屏幕输出整个表 " << endl;
cout << " 7.不想玩了,拜拜! " << endl;
cout << "请输入您的选择:" ;
cin >> b;
}
return 0;
}
#include<stdlib.h>
using namespace std;
typedef int ElemType;
const int Maxsize=100;
struct List
{
int size;
ElemType list[Maxsize];
};
void InitList(List &L)//初始化
{
L.size=0;
}
void ClearList(List &L)//清空
{
L.size=0;
}
int LenthList(List &L)//得到线性表的长度
{
return L.size;
}
bool EmptyList(List &L)//判断线性表是否为空
{
return L.size==0;
}
ElemType GetList(List &L,int pos)//找出给定序号pos的元素
{
if(pos<1 || pos>L.size)
{
cout << " pos is out range! " << endl;
exit(1);
}
return L.list[pos-1];
}
void TraverseList(List &L)//遍历线性表
{
for(int i=0; i<L.size; i++)
cout << L.list[i] << ' ';
}
bool FindList(List &L, ElemType& item)//找出给定值
{
for(int j=0; j<L.size;j++)
if(L.list[j] == item)
{
item = L.list[j];
return true;
}
return false;
}
bool UpdateList(List &L, const ElemType& item)//更新线性表的值
{
for(int k=0; k<L.size; k++)
if(L.list[k] == item)
{
L.list[k] = item;
return true;
}
return false;
}
bool InsertList(List &L, ElemType item, int pos)//按指定条件插入元素
{
if(pos<-1 || pos>L.size+1)
{
cout << "pos值无效!" << endl;
return false;
}
if(pos==0)
{
for(int l=0; l<L.size; l++)
if(item<L.list[l]) break;
pos=l+1;
}
else if(pos==-1) pos=L.size+1;
L.list[p+1]=L.list[p];
L.size++;
return true;
}
bool DeleteList(List &L, ElemType& item, int pos)//按指定条件删除元素
{
if(L.size==0)
{
cout << "线性表为空,删除无效!" << endl;
return false;
}
{
cout << "pos值无效!" << endl;
return false;
}
{
if(item==L.list[n]) break;
if(n==L.size) return false;
}
item = L.list[pos-1];
{
L.list[r-1]=L.list[r];
}
L.size--;
return true;
}
void SortList(List &L)//排序
{
ElemType x;
for(int p=1; p<L.size; p++)
{
x=L.list[p];
if(x<L.list[p]) L.list[q+1]=L.list[q];
L.list[q+1]=x;
}
}
int main()
{
int a[12]={3,4,7,9,13,16,17,34,23,12,2,49};
List t;
InitList(t);
TraverseList(t);
cout << " 欢迎来到×××的数字顺序表游戏! " << endl;
cout << " 请选择:" << endl;
cout << " 1.新建数字顺序表 " << endl;
cout << " 2.查找某数是否在表中 " << endl;
cout << " 3.插入一个数字到表中 " << endl;
cout << " 4.删除表中某数" << endl;
cout << " 5.给数字顺序表排序 " << endl;
cout << " 6.屏幕输出整个表 " << endl;
cout << " 7.不想玩了,拜拜! " << endl;
cout << "请输入您的选择:" ;
int e=0, g=0;
int z=0, h=0 ;
int f=0, y=0;
cin >> b;
for(int b1=0; ;b++)
{
switch(b)
{
case 1:
cout << "请输入线性表的长度n(n>0且n<100):" << endl;
List t1;
InitList(t1);
cin >> b;
for(; e<b; e++)
cin >> d[e];
for(; f<b; f++)
InsertList(t1, d[f],f);
TraverseList(t1);
break;
cout << "输入待查找的元素值:";
cin >> g;
if(FindList(t,g))
cout << "查找成功!" << endl;
else cout << "查找失败!" << endl;
break;
cout << "按值插入,输入待插入元素的值:";
cin >> h;
if(InsertList(t,h,0)) cout << "插入成功!" << endl;
else cout << "插入失败!" << endl;
TraverseList(t);
break;
cout << "输入待删除元素的值:" << endl;
cin >> y;
if(DeleteList(t,y,0)) cout << "删除成功!" << endl;
else cout << "删除失败!" << endl;
TraverseList(t);
break;
cout << "下面将给数字表排序:";
SortList(t);
TraverseList(t);
break;
cout << "下面将输出整个表:" << endl;
TraverseList(t);
break;
cout << " 不想玩了,拜拜! " << endl;
break;
cout << " Error " << endl;
break;
}
if(b==7) exit(1);
cout << " 欢迎来到×××的数字顺序表游戏! " << endl;
cout << " 请选择:" << endl;
cout << " 1.新建数字顺序表 " << endl;
cout << " 2.查找某数是否在表中 " << endl;
cout << " 3.插入一个数字到表中 " << endl;
cout << " 4.删除表中某数" << endl;
cout << " 5.给数字顺序表排序 " << endl;
cout << " 6.屏幕输出整个表 " << endl;
cout << " 7.不想玩了,拜拜! " << endl;
cout << "请输入您的选择:" ;
cin >> b;
}
return 0;
}
0 0
- 简单的数字顺序表游戏
- 一个简单的数字游戏
- zcmu1519 简单的数字游戏
- 简单的猜数字游戏,功能完备
- 一个简单的猜数字游戏
- java猜数字,一个简单的游戏
- UI中简单的猜数字游戏
- QT---简单的猜数字游戏
- 一个简单的猜数字游戏
- 制作一个简单的猜数字游戏
- 简单的C# 猜数字游戏
- JAVA实现简单的猜数字游戏
- 非常简单的猜数字游戏
- /*简单猜数字游戏*/
- 简单猜数字游戏
- 简单猜数字游戏
- 简单猜数字游戏
- 简单的顺序表
- 软件测试 读书笔记(思维导图)
- DeCAF: A Deep Convolutional Activation Featurefor Generic Visual Recognition阅读报告(2)
- Z-stack 2.6.1中新增的ZIGBEE_CHILD_AGING模式怎么使用?
- 解题报告 之 ZOJ 3822 Domination
- java面试题三十一
- 简单的数字顺序表游戏
- spring笔记 Bean实例化的机制
- 数据库连接池库libzdb使用教程
- 【SSH快速进阶】——Hibernate环境搭建
- Enable Nux Dextop Repository on CentOS
- Android适配器进阶之三(抽象分类适配器)
- Android学习路线图
- [LeetCode] Delete Node in a Linked List
- 无废话WCF入门教程二[什么是WCF]