主题:小菜的顺序表输入时遇到的问题~
#include<iostream>
using namespace std;
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct
{
char *elem;
int length;
int listsize;
}sqlist;
void InitList(sqlist &l)
{
l.length=0;
l.listsize=LIST_INIT_SIZE;
}
void small_list_insert(sqlist l,int i,char e)
{
char *q;
q=&l.elem[i+1];
*q=e;
++l.length;
}
void print_list(sqlist a)
{
for(int i=0;i<a.length;i++)
{
cout<<a.elem[i];
}
cout<<endl;
}
int main()
{
sqlist La;
sqlist Lb,Lc;
InitList(La);
InitList(Lb);
InitList(Lc);
char La_head,Lb_head,Lc_head;
char La_e,Lb_e,Lc_e;
int a_length;int b_length;int c_length;
cout<<"La's length is:";
cin>>a_length;
La.length=a_length;
cout<<"请输入a单词"<<endl;
cin>>La_head;
La.elem[0]=La_head;
for(int i=0;i<La.length-1;i++)
{
cin>>La_e;
small_list_insert(La,i,La_e);
}
print_list(La);
cout<<"Lb's length is:";
cin>>b_length;
Lb.length=b_length;
cout<<"请输入b单词"<<endl;
cin>>Lb_head;
Lb.elem[0]=Lb_head;
for(int j=0;j<Lb.length-1;j++)
{
cin>>Lb_e;
small_list_insert(Lb,i,Lb_e);
}
print_list(Lb);
cout<<"Lc's length is:";
cin>>c_length;
Lc.length=c_length;
cout<<"请输入c单词"<<endl;
cin>>Lc_head;
Lc.elem[0]=Lc_head;
for(int k=0;k<Lc.length-1;k++)
{
cin>>Lc_e;
small_list_insert(Lc,i,Lc_e);
}
print_list(Lc);
}
编译倒是没问题,但是输入字母的时候总是出错误终止了,不知道问题出在哪里,大虾们帮帮忙!
感激不尽[em1][em1][em1]
using namespace std;
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct
{
char *elem;
int length;
int listsize;
}sqlist;
void InitList(sqlist &l)
{
l.length=0;
l.listsize=LIST_INIT_SIZE;
}
void small_list_insert(sqlist l,int i,char e)
{
char *q;
q=&l.elem[i+1];
*q=e;
++l.length;
}
void print_list(sqlist a)
{
for(int i=0;i<a.length;i++)
{
cout<<a.elem[i];
}
cout<<endl;
}
int main()
{
sqlist La;
sqlist Lb,Lc;
InitList(La);
InitList(Lb);
InitList(Lc);
char La_head,Lb_head,Lc_head;
char La_e,Lb_e,Lc_e;
int a_length;int b_length;int c_length;
cout<<"La's length is:";
cin>>a_length;
La.length=a_length;
cout<<"请输入a单词"<<endl;
cin>>La_head;
La.elem[0]=La_head;
for(int i=0;i<La.length-1;i++)
{
cin>>La_e;
small_list_insert(La,i,La_e);
}
print_list(La);
cout<<"Lb's length is:";
cin>>b_length;
Lb.length=b_length;
cout<<"请输入b单词"<<endl;
cin>>Lb_head;
Lb.elem[0]=Lb_head;
for(int j=0;j<Lb.length-1;j++)
{
cin>>Lb_e;
small_list_insert(Lb,i,Lb_e);
}
print_list(Lb);
cout<<"Lc's length is:";
cin>>c_length;
Lc.length=c_length;
cout<<"请输入c单词"<<endl;
cin>>Lc_head;
Lc.elem[0]=Lc_head;
for(int k=0;k<Lc.length-1;k++)
{
cin>>Lc_e;
small_list_insert(Lc,i,Lc_e);
}
print_list(Lc);
}
编译倒是没问题,但是输入字母的时候总是出错误终止了,不知道问题出在哪里,大虾们帮帮忙!
感激不尽[em1][em1][em1]