为什么输入进去的数字打印之后就不一样啊
源代码
#include<iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define MAXSIZE 100
int i,j,s,b,L;
typedef char ElemType;
typedef struct
{
char *elem;
int length;
}Sqlist;
typedef int Status;
Status initList(Sqlist &L)//初始化
{L.elem=new ElemType[MAXSIZE];
if(L.elem==NULL)
exit(OVERFLOW);
L.length=0;
return OK;
}
Status writeList(Sqlist &L)
{
cout<<"输入顺序表长度"<<endl;
cin>>L.length;
cout<<"请输入%d个元素"<<endl;
for (int i=0;i<L.length;i++)
{
cin>>L.elem[i];
}
}
bool Print(Sqlist &L)//输出顺序表元素
{ if(!L.elem)
return ERROR;
cout<<"顺序表元素为:"<<endl;
for (int k=0;k<L.length;k++)
printf("%d ",L.elem[k]);
printf("\n");
return OK;
}
int main()
{
Sqlist L;
initList(L);
writeList(L);
Print(L);
return 0;
}