- 11
- 0
- 约6.49千字
- 约 7页
- 2017-01-12 发布于江苏
- 举报
线性表基本操作-示例程序02
/*00基本信息定义*/
#include stdio.h
#include string.h
#include malloc.h
#define SUCCESS 1
#define FAILURE 0
#define null 0
#define maxsize 100
typedef struct students /*定义结构体数据类型*/
{ char stuname[10];
char sex[8];
int age;
}datatype;
typedef struct /*定义线性表(顺序结构)数据类型*/
{
datatype data[maxsize];
int last;
}sequenlist;
int n;
/*定义功能选择菜单函数*/
void print()
{ printf(----线性表(顺序结构)的基本操作----\n);
printf(----------开始----------\n);
}
/*打印线性表(顺序结构)*/
void printout(sequenlist *L)
{ int i;
for(i=1; i=L-last; i++)
{
printf( [%d], i);
printf(姓名:%s 性别:%s 年龄:%d\n, L-data[i].stuname,L-data[i].sex,L-data[i].age);
printf(\n);
}
}
/*01线性表(顺序结构)的初始化*/
int InitList(sequenlist *L)
{
L = (sequenlist *)malloc(sizeof(sequenlist));
if(!L)
{
return FAILURE;
}
else
{
L-last = -1;
return SUCCESS;
}
}
/*02创建线性表(顺序结构)*/
void creatlist(sequenlist *L)
{ int i;
char tmp1[10];
int tmp3;
printf(请输入线性表中数据的个数:);
scanf(%d,n);
for(i=1; i=n; i++)
{ printf(data[%d].stuname=, i);
fflush(stdin); /*清除掉键盘缓冲区*/
scanf (%s, tmp1);
strcpy(L-data[i].stuname,tmp1);
printf(data[%d].sex=, i);
fflush(stdin); /*清除掉键盘缓冲区*/
scanf (%s, L-data[i].sex);
printf(data[%d].age=, i);
fflush(stdin); /*清除掉键盘缓冲区*/
scanf (%d, tmp3);
L-data[i].age = tmp3;
}
L-last=n;
}
/*03在第i个结点前插入元素x(note:元素从1始计数)*/
int insert(sequenlist *L, datatype x,int i)
{ int j;
if (L-last==maxsize)/*如果原线性表(顺序结构)已经满了*/
{ printf(线性表(顺序结构)已满\n);
return 0;
}
else if ((i1)||(iL-last+1)) /*如果输入的i值超出范围*/
{ printf(错了,请输入正确的i值\n);
return 0;
}
else
{ for(j=L-last; j=i; j--) /*从第i个元素起,每个元素后移一位*/
L-data[j+1]=L-data[j];
strcpy(L-data[i].stuname,x.stuname);
strcpy(L-data[i].sex,x.sex);
L-data[i].age=x.age;
L-last=L-last+1;
}
return(1);
}
/*04删除第i个结点,note:元素从1始计数*/
int dellist(sequenlist *L,int i)
{ if ((i1)||(iL-last)) /*如果输入的
您可能关注的文档
- 线性代数课件2.5.ppt
- 线性代数课件黄六1.ppt
- 线性代数第四章_线性方程组.doc
- 线性方程直接法实验 - 副本.docx
- 线性方程组§3.1 消元法.ppt
- 线性电机.docx
- 线性表(顺序存储)及其应用.doc
- 线性表的c++.doc
- 线性表的疑问.docx
- 线性表的顺序存储.doc
- 2026年中国窗饰产品市场全景调查与市场供需预测报告.docx
- 2026年中国船舶水下清洗行业深度研究报告:市场需求预测、进入壁垒及投资风险.docx
- 2026年中国船用绞车行业运行态势及十五五盈利前景预测报告.docx
- 2026年中国橱柜行业深度调研报告.docx
- 2026年中国船用绞车市场深度调研及投资前景战略分析报告.docx
- 2026年中国船用配套设备市场发展策略及投资潜力可行性预测报告.docx
- 2026年中国储能材料行业运营态势与投资前景预测分析报告.docx
- 2026年中国储氢材料行业运营现状及发展规划分析报告.docx
- 2026年中国传真机市场深度研究及投资前景咨询报告.docx
- 2026年中国储能变流器(PCS)产业深度评估与发展前景趋势分析研究报告.docx
原创力文档

文档评论(0)