#include<iostream>
#include<malloc.h>
using namespace std;
typedef struct SqList{
int *elem;
int length;
int listsize;
};
void InistSqList(SqList &L) //线性表的创建(初始化)
{
L.elem=(int *)malloc(20*sizeof(int)); //动态分配内存空间
L.length=0;
L.listsize=20;
}
void CreateSqList(SqList &L) //线性表的输入
{
int i=0;
cin>>L.elem[i];
while(L.elem[i]!=-1 && i=19) //线性表结束输入的标志
{
L.length ++;
i++;
cin>>L.elem [i];
}
}
void PrintSqList(SqList L) //线性表的输出
{
int i;
for(i=0;i<L.length;i++){
cout<<L.elem[i]<<' ';
}
}
int main(){
SqList L;
InistSqList(L);
CreateSqList(L);
PrintSqList(L);
return 0;
}
线性表的基本创建和输入输出
最新推荐文章于 2022-10-31 20:23:56 发布