#include<iostream>
#include<string.h>
#include<conio.h>
using namespace std;
#define MAXLEN 100
typedef struct
{
char key[];
char name[];
int age;
}DATA;
typedef struct
{
DATA ListData[MAXLEN + ];
int ListLen;
}SLType;
void SLInit(SLType*SL)//初始化顺序表
{
SL->ListLen = ;
}
int SLLength(SLType*SL)//返回顺序表的元素数量
{
return(SL->ListLen);
}
int SLInsert(SLType*SL, int n, DATA data)//只在表间插入
{
int i;
if (SL->ListLen >= MAXLEN)
{
cout << "顺序表已满,不能插入结点!\n";
return ;
}
if (n< || n>SL->ListLen - )//插入结点序号不正确
{
cout<<"插入结点的序号错误";
return ;
}
for (i = SL->ListLen; i >= n; i--)
{
SL->ListData[i + ] = SL->ListData[i];
}
SL->ListData[n] = data;
SL->ListLen++;
return ;//成功插入返回1
}
int SLAdd(SLType*SL, DATA data)
{
if (SL->ListLen >= MAXLEN)
{
cout << "顺序已满,不能再添加结点了" << endl;
return ;
}
SL->ListData[++SL->ListLen] = data;
return ;
}
int SLDelete(SLType* SL, int n)
{
int i;
if (n< || n>SL->ListLen + )
{
cout << "删除结点序号错误,不能删除";
return ;
}
for (i = n; i < SL->ListLen; i++)
{
SL->ListData[i] = SL->ListData[i + ];
}
SL->ListLen--;
return ;
}
DATA*SLFindByNum(SLType*SL, int n)
{
if (n< || n>SL->ListLen + )
{
cout << "结点序号错误,不能返回结点";
return NULL;
}
return &(SL->ListData[n]);
}
int SLFindByCont(SLType*SL, char *key)
{
int i;
for (i = ; i < SL->ListLen; i++)
{
if (strcmp(SL->ListData[i].key, key) == )
{
return i;//返回结点序号
}
}
return ;
}
int SLALL(SLType*SL)
{
int i;
for (i = ; i <=SL->ListLen; i++)
{
cout << SL->ListData[i].key << SL->ListData[i].name << SL->ListData[i].age << endl;
}
return ;
}
int main()
{
int i;
SLType SL;
DATA data;
DATA *pdata;
char key[];
cout << "顺序操作表演示" << endl;
SLInit(&SL);
cout << "链表初始化完成" << endl;
do
{
cout << "输入添加的结点(学号 姓名 年龄):" << endl;
fflush(stdin);//清空输入缓冲区
cin>>data.key>>data.name>>data.age;
if (data.age)//若年龄不为0
{
if (!SLAdd(&SL, data))
{
break;
}
}
else
{
break;
}
} while ();
cout << "顺序表中的结点顺序为:" << endl;
SLALL(&SL);//显示所有的结点数据
fflush(stdin);
cout << "要取出结点的序号:" << endl;
cin >> i;
pdata = SLFindByNum(&SL, i);
if (pdata)
{
cout << i << pdata->key << pdata->name << pdata->age << endl;
}
fflush(stdin);
cout << "要查找结点的关键字" << endl;
cin >> key;
i = SLFindByCont(&SL, key);
pdata = SLFindByNum(&SL, i);
if (pdata)
{
cout << i << pdata->key << pdata->name << pdata->age << endl;
}
getch();
return ;
}

最新文章

  1. 【Delphi】最小化事件捕捉
  2. html 5新特性 --用SVG绘制的微信logo
  3. Eclipse 中隐藏的 5 个非常有用的功能
  4. SQL Server Data Tool 嘹解(了解)一下 SSDT -摘自网络
  5. Bash For Loop Examples
  6. Java cookie的使用
  7. UVA1452|LA4727-----Jump------经典的约瑟夫公式的变形(DP)
  8. 从0.5开始学Java 零
  9. 基于RBAC的权限设计模型
  10. 【转】FLEX中SharedObject介绍及应用
  11. Ext 常用组件解析
  12. Codeforces 343E Pumping Stations
  13. 【python】正则替换
  14. javascript 值类型和引用类型
  15. Java编程思想 学习笔记10
  16. maven上传jar包到nexus私服后的存放路径 以及 使用IDEA上传jar包的步骤
  17. Effective Java (6) - 消除过期的对象引用
  18. 【python-opencv】17-形态学操作-腐蚀与膨胀
  19. new operator
  20. linux上设置mysql编码

热门文章

  1. 「Luogu P5494 【模板】线段树分裂」
  2. dp - 活动选择问题
  3. 110、Java中String类之字符串文本拆分
  4. 107、Java中String类之判断开头或结尾
  5. ajax的分页查询
  6. vue.js使用更简单的方法制作带删除功能的tooolist
  7. 用java实现输出英文小说飘中出现次数最多的前N个单词(附:使用文件读写)
  8. linux之我的互联网面试经验
  9. js正则 - 限制用户名只能中文、字母和数字 , 不能包含特殊字符
  10. centos 6.5安装NodeJS