数据结构线性表C++编程题目,高手来!!!

#include<iostream.h>#include<stdlib.h>#definelist_init_size100;#definelistincrement10... #include<iostream.h>
#include<stdlib.h>
#define list_init_size 100;
#define listincrement 10;
#define OVERFLOW 0;
#define ERROR 0;
#define OK 1;
typedef struct {
int *elem;
int length;
int size;
}sqlist;
int list_init(sqlist &l)
{l.elem=(int*)malloc(list_init_size * sizeof(int));
if(!l.elem) exit(OVERFLOW);
l.length=0;
l.listsize=list_init_size;
return OK;
}
int list_insert(sqlist &l,int i,int e)
{
int *newbase,*p,*q;
if(i<1||i>l.length+1)return ERROR;
if(l.length>=l.listsize){
newbase=(int*)realloc(l.elem,
(l.listsize+listincrement)*sizeof(int));
if(!newbase)exit(OVERFLOW);
q=&(l.elem[i-1]);
for(p=&(l.elem[l.length-1];p>=q;--p)
*(p+1)=*p;
*q=e;
++l.length;
return OK;
}
int locate_elem(sqlist l,int e)
{int *p=l.elem,*q=l.elem+l.length-1;
for(p=l.elem;p<=q;++p)
if(*p==e)
return p-l.elem+1;
return ERROR;
}int list_delete(sqlist &l,int i,int &e)
{
if(i<1||i>l.size)return ERROR;
int *p,*q;
p=&(l.elem[i-1]);
e=*p;
q=l.elem+l.length-1;
for(++p;p<=q;++p)
*(p-1)=*p;
l.length--;
return OK;
}

void main()
{
sqlist data;
int i,e,n;
list_init(data);
cout<<"Input number n: ";
cin>>n;
cout<<"Input "<<n<<" numbers: ";
for(i=0;i<n;++i)
{
cin>>e;
list_insert(data,data.length+1,e);
}
cout<<"Input the number's adress: ";
cin>>n;
list_delete(data,n,e);
cout<<"The rest number in the list: ";
for(i=0;i<data.length ;++i)
cout<<data.elem[i]<<" ";
cout<<endl;
}

运行了20个错误,我无语了……Compiling...
01.cpp
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(14) : error C2143: syntax error : missing ')' before ';'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(14) : error C2059: syntax error : ')'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(14) : error C2100: illegal indirection
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(15) : error C2143: syntax error : missing ')' before ';'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(15) : error C2059: syntax error : ')'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(17) : error C2039: 'listsize' : is not a member of 'sqlist'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(8) : see declaration of 'sqlist'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(24) : error C2039: 'listsize' : is not a member of 'sqlist'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(8) : see declaration of 'sqlist'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(26) : error C2039: 'listsize' : is not a member of 'sqlist'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(8) : see declaration of 'sqlist'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(26) : error C2143: syntax error : missing ')' before ';'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(26) : error C2143: syntax error : missing ')' before ';'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(26) : error C2059: syntax error : ')'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(26) : error C2059: syntax error : ')'
……………………
我们老师最后调试到还有3个,她也不会了……
高手来帮忙啊,感激不尽!!!
啊!原来如此……谢谢啊!
但是还有5个啊,能帮忙吗??麻烦了啊!!!
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(29) : error C2143: syntax error : missing ')' before ';'
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(36) : error C2601: 'locate_elem' : local function definitions are illegal
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(42) : error C2601: 'list_delete' : local function definitions are illegal
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(55) : error C2601: 'main' : local function definitions are illegal
g:\vb6.0\vc6\myprojects\数据结构1\01.cpp(76) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

01.obj - 5 error(s), 0 warning(s)
展开
 我来答
瑨霖
2010-12-15 · 超过12用户采纳过TA的回答
知道答主
回答量:32
采纳率:0%
帮助的人:0
展开全部
int list_insert(sqlist &l,int i,int e) 里面少了一个反大括号,所以导致后面有3个莫名其妙的错误
编程要养好习惯,把格式排整齐点,我改的没语法错误了。。。
#include<iostream.h>
#include<stdlib.h>
#define list_init_size 100
#define listincrement 10
#define OVERFLOW 0
#define ERROR 0
#define OK 1

typedef struct list{
int *elem;
int length;
int listsize;//与后面不对应size
}sqlist;

int list_init(sqlist &l)
{
l.elem=(int*)malloc(list_init_size * sizeof(int));
if(!l.elem) exit(OVERFLOW);
l.length=0;
l.listsize=list_init_size;//
return OK;
}
int list_insert(sqlist &l,int i,int e)
{
int *newbase,*p,*q;
if(i<1||i>l.length+1)
return ERROR;
if(l.length>=l.listsize)
{
newbase=(int*)realloc(l.elem, (l.listsize+listincrement)*sizeof(int));
if(!newbase)exit(OVERFLOW);
q=&(l.elem[i-1]);
for(p=&(l.elem[l.length-1]);p>=q;--p)//
*(p+1)=*p;
*q=e;
++l.length;
}//**********你少了一个反括号,不知道你是不是要加到这个地方
return OK;
}
int locate_elem(sqlist l, int e)
{
int *p=l.elem,*q=l.elem+l.length-1;
for(p=l.elem;p<=q;++p)
if(*p==e)
return p-l.elem+1;
return ERROR;
}
int list_delete(sqlist &l,int i,int &e)
{
if(i<1||i>l.listsize)
return ERROR;
int *p,*q;
p=&(l.elem[i-1]);
e=*p;
q=l.elem+l.length-1;
for(++p;p<=q;++p)
*(p-1)=*p;
l.length--;
return OK;
}

void main()
{
sqlist data;
int i,e,n;
list_init(data);
cout<<"Input number n: ";
cin>>n;
cout<<"Input "<<n<<" numbers: ";
for(i=0;i<n;++i)
{
cin>>e;
list_insert(data,data.length+1,e);
}
cout<<"Input the number's adress: ";
cin>>n;
list_delete(data,n,e);
cout<<"The rest number in the list: ";
for(i=0;i<data.length ;++i)
cout<<data.elem[i]<<" ";
cout<<endl;
}
光点科技
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件... 点击进入详情页
本回答由光点科技提供
歧靖Mw
2010-12-17 · TA获得超过100个赞
知道答主
回答量:193
采纳率:0%
帮助的人:106万
展开全部
#include<iostream.h>
#include<stdlib.h>
#define list_init_size 100
#define listincrement 10
#define OVERFLOW 0
#define ERROR 0
#define OK 1
typedef struct {
int *elem;
int length;
int size;
}sqlist;
int list_init(sqlist &l)
{
l.elem=(int*)malloc(list_init_size * sizeof(int));
if(!l.elem) exit(OVERFLOW);
l.length=0;
l.size=list_init_size;
return OK;
}
int list_insert(sqlist &l,int i,int e)
{
int *newbase,*p,*q;
if(i<1||i>l.length+1)return ERROR;
if(l.length>=l.size){
newbase=(int*)realloc(l.elem,
(l.size+listincrement)*sizeof(int));
if(!newbase)
exit(OVERFLOW);
q=&(l.elem[i-1]);
for(p=&(l.elem[l.length-1]);p>=q;--p)
*(p+1)=*p;
*q=e;
++l.length;
return OK;
}
return OK;
}
int locate_elem(sqlist l,int e)
{
int *p=l.elem,*q=l.elem+l.length-1;
for(p=l.elem;p<=q;++p)
if(*p==e)
return p-l.elem+1;
return ERROR;
}int list_delete(sqlist &l,int i,int &e)
{
if(i<1||i>l.size)return ERROR;
int *p,*q;
p=&(l.elem[i-1]);
e=*p;
q=l.elem+l.length-1;
for(++p;p<=q;++p)
*(p-1)=*p;
l.length--;
return OK;
}

void main()
{
sqlist data;
int i,e,n;
list_init(data);
cout<<"Input number n: ";
cin>>n;
cout<<"Input "<<n<<" numbers: ";
for(i=0;i<n;++i)
{
cin>>e;
list_insert(data,data.length+1,e);
}
cout<<"Input the number's adress: ";
cin>>n;
list_delete(data,n,e);
cout<<"The rest number in the list: ";
for(i=0;i<data.length ;++i)
cout<<data.elem[i]<<" ";
cout<<endl;
}
没错了
首先宏定义不要加分号在后面 函数结束之后别忘了有} 注意在结构体中自己定义的数据使用的名称 即变量名
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
依米黄
2010-12-15
知道答主
回答量:16
采纳率:0%
帮助的人:0
展开全部
你好
#define list_init_size 100;
#define listincrement 10;
#define OVERFLOW 0;
#define ERROR 0;
#define OK 1;
你初学吗?
你将list_init_size 宏定义成 “100;”分号不该要 这是宏 不需要这个分号应该改成:
#define list_init_size 100
#define listincrement 10
#define OVERFLOW 0
#define ERROR 0
#define OK 1
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
qftprp
2010-12-16 · TA获得超过443个赞
知道答主
回答量:311
采纳率:0%
帮助的人:239万
展开全部
//"orderlist.h"
typedef int DataType;
class ListNode
{
public:
DataType value;
ListNode* pnext;

ListNode()
{
pnext = NULL;
}

ListNode(DataType item)
{
value = item;
pnext = NULL;
}
};

class OrderLinkList
{
public:
ListNode* phead;

OrderLinkList()
{
phead = new ListNode;
}
OrderLinkList(OrderLinkList& L);
OrderLinkList& operator=(OrderLinkList&);

void print();

void insert(DataType item);
void remove(DataType item);
static OrderLinkList merge(OrderLinkList& L1, OrderLinkList& L2);

~OrderLinkList();
};

//"orderlist.cpp"
#include <iostream>
#include "orderlist.h"
using namespace std;

OrderLinkList::OrderLinkList(OrderLinkList& L)
{
phead = new ListNode;
phead->pnext = L.phead->pnext;
L.phead->pnext = NULL;
}

OrderLinkList& OrderLinkList::operator=(OrderLinkList& L)
{
phead->pnext = L.phead->pnext;
L.phead->pnext = NULL;
return *this;
}

void OrderLinkList::print()
{
ListNode* p = phead->pnext;
while(p)
{
cout<<p->value<<" ";
p = p->pnext;
}
cout<<endl;
}

void OrderLinkList::insert(DataType item)
{
ListNode* p = new ListNode(item);

ListNode* q = phead;
while(q->pnext)
{
if(q->pnext->value>=item)
{
p->pnext = q->pnext;
q->pnext = p;
}
q = q->pnext;
}
if(p->pnext==NULL)
q->pnext = p;

}

void OrderLinkList::remove(DataType item)
{
ListNode* p = phead;
while(p->pnext)
{
if(p->pnext->value==item)
{
ListNode* q = p->pnext;
p->pnext = q->pnext;
delete q;
}
p = p->pnext;
}
}

OrderLinkList OrderLinkList::merge(OrderLinkList& L1,OrderLinkList& L2)
{
if(!(L1.phead->pnext))return L2;
if(!(L2.phead->pnext))return L1;
OrderLinkList L3;
ListNode* p3 = L3.phead;
ListNode* p1 = L1.phead;
ListNode* p2 = L2.phead;
ListNode* tmp = p3;

while(p1->pnext&&p2->pnext)
{
if(p1->pnext->value<p2->pnext->value)
{
tmp->pnext = p1->pnext;
p1->pnext = p1->pnext->pnext;
tmp = tmp->pnext;
}
else
{
tmp->pnext = p2->pnext;
p2->pnext = p2->pnext->pnext;
tmp = tmp->pnext;
}
}
if(p1->pnext)
{
tmp->pnext = p1->pnext;
p1->pnext = NULL;
}
if(p2->pnext)
{
tmp->pnext = p2->pnext;
p2->pnext = NULL;
}
return L3;
}

OrderLinkList::~OrderLinkList()
{
ListNode* tmp;
while(phead)
{
tmp = phead;
phead = phead->pnext;
delete tmp;
}
}

void main()
{
OrderLinkList L1;
for(DataType i=1;i<10;i=i+2)
L1.insert(i);
L1.print();
OrderLinkList L2;
for(DataType j=2;j<=10;j=j+2)
L2.insert(j);
L2.print();
L2.remove(6);
L2.print();
OrderLinkList L3 ;
L3 = OrderLinkList::merge(L1,L2);
L3.print();
return;
}

无聊的人写了一个无聊的函数,给分
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式