#include <stdio.h>
#include <stdlib.h>
#define SizeMax 10
typedef char ElemType;
typedef struct
{
ElemType data[SizeMax];
int length;
} SqList;
void InitList(SqList *&L) //建立顺序表
{
L=(SqList*)malloc(sizeof(SqList));
L->length=0;
}
void Insert(SqList *&L,ElemType n) //插入顺序表
{
L->data[L->length]=n;
L->length++;
}
void Print(SqList *L) //输出顺序表
{
for(int i=0; i<L->length; i++)
printf(i!=L->length-1?"%c ":"%c\n",L->data[i]);
}
void PrintLength(SqList *L) //输出长度
{
printf("%d\n",L->length);
}
bool SqNull(SqList *L) //判断是否为空
{
if(L->length)return 1;
return 0;
}
void PrintData(SqList *L,int n) //输入第n个元素
{
if(L->length<n)return;
printf("%c\n",L->data[n-1]);
}
int Find(SqList *L,ElemType a) //找到为a的位置
{
for(int i=0; i<L->length; i++)
if(L->data[i]==a)return i+1;
return 0;
}
void Insertinto(SqList *&L,int n,ElemType f)
{
for(int i=L->length; i>=n; i--)
L->data[i]=L->data[i-1];
L->data[n-1]=f;
L->length++;
}
void Delete(SqList *&L,int n)
{
for(int i=n-1; i<L->length-1; i++)
L->data[i]=L->data[i+1];
L->length--;
}
#include <stdlib.h>
#define SizeMax 10
typedef char ElemType;
typedef struct
{
ElemType data[SizeMax];
int length;
} SqList;
void InitList(SqList *&L) //建立顺序表
{
L=(SqList*)malloc(sizeof(SqList));
L->length=0;
}
void Insert(SqList *&L,ElemType n) //插入顺序表
{
L->data[L->length]=n;
L->length++;
}
void Print(SqList *L) //输出顺序表
{
for(int i=0; i<L->length; i++)
printf(i!=L->length-1?"%c ":"%c\n",L->data[i]);
}
void PrintLength(SqList *L) //输出长度
{
printf("%d\n",L->length);
}
bool SqNull(SqList *L) //判断是否为空
{
if(L->length)return 1;
return 0;
}
void PrintData(SqList *L,int n) //输入第n个元素
{
if(L->length<n)return;
printf("%c\n",L->data[n-1]);
}
int Find(SqList *L,ElemType a) //找到为a的位置
{
for(int i=0; i<L->length; i++)
if(L->data[i]==a)return i+1;
return 0;
}
void Insertinto(SqList *&L,int n,ElemType f)
{
for(int i=L->length; i>=n; i--)
L->data[i]=L->data[i-1];
L->data[n-1]=f;
L->length++;
}
void Delete(SqList *&L,int n)
{
for(int i=n-1; i<L->length-1; i++)
L->data[i]=L->data[i+1];
L->length--;
}