- 6
- 0
- 约1.01万字
- 约 7页
- 2016-10-20 发布于贵州
- 举报
C语言程序——性顺序表
程序清单:
线性顺序表1:
#define MaxSize 100
typedef char ET;
#include stdio.h
#include string.h
#include stdlib.h
struct list
{
ET alist[MaxSize];
int size;
};
void Setnull(struct list *p)
{
if(p-alist[0]= =NULL)
exit(1);
else
{
p-alist[0]=NULL;
p-size=0;
}
}
int Length(struct list *p)
{
return strlen(p-alist);
}
ET Get(struct list*p,int i)
{
if(i0||ip-size)
{
printf(the number is wrong!\n);
exit(1);
}
else return (p-alist[--i]);
}
int Locate(struct list *p,ET x)
{
int j;
for(j=0;p-alist[j]!=NULL;j++)
if(p-alist[j]= =x)break;
return ++j;
}
void Insert(struct list *p,int i,ET x)
{
if(p-size= =MaxSize)
{
printf(the list is full\n);
exit(1);
}
int j;
j=p-size;
for(;j=(i-1);j--)
p-alist[j+1]=p-alist[j];
p-alist[i-1]=x;
p-size=p-size+1;
}
void Delete(struct list *p,int i)
{
if(i0||ip-size)
{
printf(the number is wrong!\n);
exit(1);
}
for(;p-alist[i]!=NULL;i++)
p-alist[i-1]=p-alist[i];
p-alist[i-1]=NULL;
p-size=p-size-1;
}
void Display(struct list *p)
{
int i;
for(i=0;p-alist[i+1]!=NULL;i++)
printf(%c-,p-alist[i]);
printf(%c,p-alist[i]);
printf(\n);
}
void main()
{
int i,j,k,l;
ET a,b,c;
struct list p;
Setnull(p);
printf(please enter the elements:\n);
scanf(%s,p.alist);
p.size=Length(p);
printf(my list is:\n);
Display(p);
printf(the length of the list is %d\n,p.size);
printf(please enter the elements you want to search:\n);
scanf(%s,b);
j=Locate(p,b);
printf(%cs position is:%d\n,b,j);
printf(please enter the position you want to search:);
scanf(%d,i);
a=Get(p,i);
printf(the element in position %d is:%c\n,i,a);
printf(please enter the position and the element:);
scanf(%d,%c,k,c);
Insert(p,k,c);
printf(after insert %c,the list is:\n,c);
Display(p);
printf(please enter the position you want to delete:\n);
scanf(%d,l);
Delete(p,l);
printf(after delete the element in position %d,the list is:\n,l);
Display(p);
printf(\n);
}
线性顺序表2:
#include stdio.h
#include stdlib.h
#include time.
您可能关注的文档
- BXQ防爆电磁动箱和防爆磁力启动箱价格.docx
- bxx51防爆力检修箱和现场防爆控制箱价格.docx
- BY2580直电阻测试仪说明书.doc
- BYH系列隔爆防爆环形荧光灯和GTBD342矿用隔爆型投光灯价格.docx
- BYLabel码打印机驱动中如何设置纸张规格.doc
- BYY-9_2防爆安全出口灯和SBD3106防爆安全标志灯价格.docx
- BYY防爆箭头示灯和BAYD51-9_20防爆标志灯.价格.docx
- BYY安全出口爆标志灯DC6V和220V照明应急两用灯价格.docx
- BYY防爆箭头示灯和LED防爆双面标志灯220V价格.docx
- BZM-DIP10粉尘防爆照明开关和防爆型行程开关价格.docx
- 2025年全国演出经纪人员资格认定考试试卷带答案(研优卷).docx
- 2025年全国演出经纪人员资格认定考试试卷完整版.docx
- 2025年全国演出经纪人员资格认定考试试题库及完整答案.docx
- 2025年全国演出经纪人员资格认定考试试卷完美版.docx
- 2025年全国演出经纪人员资格认定考试试卷含答案(实用).docx
- 2025年全国演出经纪人员资格认定考试试卷及答案(各地真题).docx
- 2025年下半年内江市部分事业单位公开考试招聘工作人员(240人)备考题库附答案.docx
- 2025年全国演出经纪人员资格认定考试试卷及答案1套.docx
- 2025年下半年四川成都市郫都区面向社会引进公共类事业单位人员2人备考题库最新.docx
- 2025年下半年内江市部分事业单位公开考试招聘工作人员(240人)备考题库附答案.docx
原创力文档

文档评论(0)