|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
//预定义常量
#include<stdio.h>
#define MAX 50//线性表存储空间的初始分配量
#define listincrement 10//存储空间分配增量
//定义一种结构类型
typedef struct
{
int *elem;
int length;
int listsize;
}SqList;
//建立一个线性表
void CreatList(SqList &L)
{
L.elem=(int*)malloc(Max*sizeof(int));//赋予L Max大的基地址
if(!L.elem)
return 0;//若赋予失败返回
L.listsize=0;//就当前给表增加一个大小为listsize的数据元素空间
L.length=8;//表的长度为8
printf("输入表的长度为:");
scanf("%d",&L.length);
for(int i=0;i<L.length;i++)
scanf("%d",&L.length[i]);
return ;
}
//在某个位置增加元素
void Listinsert(&L,m,n)//m为插入元素的位置,n为插入元素的值
{
int m,n,*q,*p;
q=&L.length[m-1];
p=L.length
printf("请输入要插入元素在表中的位置:\n");
scanf("%d",&m);
printf("请输入要插入元素的值\n");
scanf("%d",&n);
if(m<0||m>L.length)
return 0;
for(p>q;p<=L.length;p++)
L.elem[p++];
L.length++;
return 0;
}
int main()
{
CreatList(SqList &L);
Listinsert(&L,3,8);
return 0;
}
C:\Users\Administrator\Desktop\p2.cpp(15) : error C2065: 'malloc' : undeclared identifier
C:\Users\Administrator\Desktop\p2.cpp(15) : error C2065: 'Max' : undeclared identifier
C:\Users\Administrator\Desktop\p2.cpp(17) : error C2562: 'CreatList' : 'void' function returning a value
C:\Users\Administrator\Desktop\p2.cpp(13) : see declaration of 'CreatList'
C:\Users\Administrator\Desktop\p2.cpp(23) : error C2109: subscript requires array or pointer type
C:\Users\Administrator\Desktop\p2.cpp(23) : error C2102: '&' requires l-value
C:\Users\Administrator\Desktop\p2.cpp(27) : error C2065: 'L' : undeclared identifier
C:\Users\Administrator\Desktop\p2.cpp(27) : error C2065: 'm' : undeclared identifier
C:\Users\Administrator\Desktop\p2.cpp(27) : error C2065: 'n' : undeclared identifier
C:\Users\Administrator\Desktop\p2.cpp(28) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
C:\Users\Administrator\Desktop\p2.cpp(46) : error C2275: 'SqList' : illegal use of this type as an expression
C:\Users\Administrator\Desktop\p2.cpp(11) : see declaration of 'SqList'
C:\Users\Administrator\Desktop\p2.cpp(47) : error C2065: 'Listinsert' : undeclared identifier
执行 cl.exe 时出错.
p2.obj - 1 error(s), 0 warning(s)
|
|