匪夷所思
这段代码编译无任何问题,可是就是输不出最后结果,高人请赐教----------sqlist.h-----
#define ElemType char
#define max 100
typedef struct
{
ElemType elem[max];
int length;
}sqlist;
------------------------------
#include "sqlist.h"
#include <iostream>
using namespace std;
void Insert(sqlist *L,int i,ElemType e)
{
if(i<1||i>L->length)
{
cout<<"Insert illegally!"<<endl;
}
else
{
char *p=0;
char *q=0;
q=&(L->elem[i-1]);
for(p=&(L->elem[L->length-1]);p>=q;p--)
{
*(p++)=*p;
}
*q=e;
L->length++;
}
}
void main()
{
sqlist l;
int p,q,m;
char e;
cout<<"请输入长度p:"<<endl;
cin>>l.length;
cout<<"请输入元素:"<<endl;
for(q=0;q<l.length;q++)
{
cin>>l.elem[q];
}
cout<<"请输入要插入的位置m:"<<endl;
cin>>m;
cout<<"请输入要插入的元素e:"<<endl;
cin>>e;
Insert(&l,m,e);
for(q=0;q<l.length;q++)
{
cout<<l.elem[q];
}
}