📄 xianxingbiao.c
字号:
/* 标准文档模板SHY1_1 线性表*/
#include "Stdio.h"
#include "Conio.h"
#include <stdio.h>
#include <conio.h>
#define Null 0
#define MaxSize 1024
typedef int DataType;
typedef struct node
{
DataType data[MaxSize];
int last;
}SequenList;
void PrintOut(SequenList *L);
int Delete(SequenList *L,int i);
void CreateList(SequenList *L);
int Insert(SequenList *L,DataType x,int i);
void main()
{
SequenList MyList,*L;
char cmd;
int i,x;
L=&MyList;
do
{
do
{
printf("\n\tc,C......Create List\n");
printf("\n\ti,I .....Insert");
printf("\n\td,D......Delete");
printf("\n\tq,Q......Quit\n\tYour choice:");
cmd=getchar();
}while((cmd!='d')&&(cmd!='D')&&(cmd!='q')&&(cmd!='Q')&&(cmd!='i')&&(cmd!='I')
&&(cmd !='c')&&(cmd !='C'));
switch(cmd)
{
case 'c':
case 'C':
CreateList(L);
break;
case 'i':
case 'I':
printf("\nInput the data to be inserted:");
scanf("%d",&x);
printf("\nInput the poistion to be inserted:");
printf("\n(1--%d)\n",(L->last+2));
scanf("%d",&i);
Insert(L,x,i);
PrintOut(L);
getch();
break;
case 'd':
case 'D':printf("\nInput the index_No of data to be deleted\n");
printf("\n(1---%d):\n",(L->last+1));
scanf("%d",&i);
Delete(L,i);
PrintOut(L);
getch();
break;
default: break;
}
}while((cmd!='q') && (cmd!='Q'));
}
int Insert(SequenList *L,DataType x,int i)
{
SequenList *p;
int j;
p=L;
if(p->last==(MaxSize-1))
{
printf("\nOverflow!");
return Null;
}
else
if( (i<1) ||( i>(p->last+2)))
{
printf("range error");
return Null;
}
else
{
for(j=L->last;j>=i-1;j--)
L->data[j+1]=L->data[j];
L->data[i-1]=x;
L->last=L->last+1;
}
return (1);
}
void PrintOut(SequenList *L)
{
int i;
for(i=0;i<=L->last;i++)
{
printf("data[%d]=",i+1);
printf("%d\t",L->data[i]);
if((i!=0)&&((i%4)==0)) printf("\n");
}
}
int Delete(SequenList *L,int i)
{
int j;
if((i<1)||(i>L->last+1))
{
printf("range error");
return Null;
}
else
{
for(j=i;j<=L->last;j++)
L->data[j-1]=L->data[j];
L->last--;
}
return (1);
}
void CreateList(SequenList *L)
{
int n,i;
int mydata;
printf("\nPlease input total number of data item\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("data[%d]=",i+1);
scanf("%d",&mydata);
L->data[i]=mydata;
}
L->last=n-1;
printf("\nPress any key to continue\n");
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -