关于两个线性表的合并问题 求大虾指点

wwwzkl 2012-04-04 10:37:48
#include<stdio.h>
#include<stdlib.h>
#define LIST_INIT_SIZE 80
typedef int Status;
#define OK 1
#define OVERFLOW -2
typedef char ElemType;
typedef struct
{
ElemType *elem;
int length;
int listsize;
} SqList;


Status InitList_Sq(SqList &L)
{
L.elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L.elem) exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}


void Create_Sq(SqList &L){ //创建顺序表
int i,n;
printf("创建一个有序表:\n");
printf("输入有序表中元素的个数:");
scanf("%d",&n);
L.length=n;
for(i=0;i<n;i++){
printf("输入第%d个元素的值:",i+1);
scanf("%d",&L.elem[i]);
printf("\n");
}
}


void Disp_Sq(SqList L){ //输出函数
int i,n;
n=L.length;
for(i=0;i<n;i++)
printf("%5d",L.elem[i]);
printf("\n");
}

void change(SqList &L) //使数据表La 从小到大排列
{ ElemType t;int n,i,j;//n为length,i,j为循环变量,t中间变量
n=L.length;
for(i=0;i<n-1;i++)
for(j=0;j<n-1-i;j++){
if(L.elem[i]>L.elem[i+1])
t=L.elem[i+1];
L.elem[i+1]=L.elem[i];
L.elem[i]=t;

}





}



void Combine(SqList &La, SqList &Lb) //把Lb插到La中,并形成从小到大的新La
{ ElemType *q,*p; int m=La.length,n=Lb.length,j,i;
for(j=0;j<n;j++) //去Lb中的第j个
for(i=0;i<m;i++) //与La.elem 逐个比较,
{
if(Lb.elem[j]<La.elem[i])//如果Lb的第j+1个数据比La第i+1个数据小则插入
{q=&La.elem[i]; //取插入地址
for(p=&La.elem[n-1];p>=q;p--)*(p)=*(p+1); //移出空位
*q=Lb.elem[j];
La.length++;
}

else if(Lb.elem[j]>La.elem[m-1]){ //Lb的第j+1个比La的最后一个还大,直接加在La的尾处
La.elem[m]=Lb.elem[j];
La.length++;
}
}
}

void main()
{
Status z1,z2; //定义表示状态的数
SqList La,Lb;
z1=InitList_Sq(&La);
z2=InitList_Sq(&Lb);
printf("创建有序数La");
Create_Sq(&La);
printf("创建有序数Lb");
Create_Sq(&Lb);
change(&La);
printf("合并前La:\n");
Disp_Sq(La);
printf("合并前Lb:\n");
Disp_Sq(Lb);
Combine(&La,&Lb);
printf("合并后,新的有序数为:\n");

Disp_Sq(La);

}

反馈的错误提示如下:
E:\C 语言工程文件\数据结构试验01\shujjg01.cpp(91) : error C2664: 'InitList_Sq' : cannot convert parameter 1 from 'SqList *' to 'SqList &'
A reference that is not to 'const' cannot be bound to a non-lvalue
E:\C 语言工程文件\数据结构试验01\shujjg01.cpp(92) : error C2664: 'InitList_Sq' : cannot convert parameter 1 from 'SqList *' to 'SqList &'
A reference that is not to 'const' cannot be bound to a non-lvalue
E:\C 语言工程文件\数据结构试验01\shujjg01.cpp(94) : error C2664: 'Create_Sq' : cannot convert parameter 1 from 'SqList *' to 'SqList &'
A reference that is not to 'const' cannot be bound to a non-lvalue
E:\C 语言工程文件\数据结构试验01\shujjg01.cpp(96) : error C2664: 'Create_Sq' : cannot convert parameter 1 from 'SqList *' to 'SqList &'
A reference that is not to 'const' cannot be bound to a non-lvalue
E:\C 语言工程文件\数据结构试验01\shujjg01.cpp(97) : error C2664: 'change' : cannot convert parameter 1 from 'SqList *' to 'SqList &'
A reference that is not to 'const' cannot be bound to a non-lvalue
E:\C 语言工程文件\数据结构试验01\shujjg01.cpp(102) : error C2664: 'Combine' : cannot convert parameter 1 from 'SqList *' to 'SqList &'
A reference that is not to 'const' cannot be bound to a non-lvalue
执行 cl.exe 时出错.

数据结构试验01.exe - 1 error(s), 0 warning(s)
...全文
205 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwwzkl 2012-04-05
  • 打赏
  • 举报
回复
在数据结构中;
typedef struct //这个是定义
{
ElemType *elem;
int length;
int listsize;
} SqList;


Status InitList_Sq(SqList &L)//这个是初始化
{
L.elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L.elem) exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}
请问:
L.elem[i] 这不是应该是指针来的吗?为什么我看到“q=&L.elem[i-1] //qw为插入地址”这样的语句?
wwwzkl 2012-04-05
  • 打赏
  • 举报
回复
功能是把两组无序的数合并并且从小到大排列
rucypli 2012-04-04
  • 打赏
  • 举报
回复
没看明白

2,209

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 其他数据库
社区管理员
  • 其他数据库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧