| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 557 人关注过本帖
标题:一个单链表操作,错误好多啊,是不是少了什么头文件?
只看楼主 加入收藏
abc594986308
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:168
专家分:116
注 册:2013-3-18
结帖率:82.93%
收藏
已结贴  问题点数:17 回复次数:2 
一个单链表操作,错误好多啊,是不是少了什么头文件?
#include <stdio.h>
#define ok 1
#define error 0
#define overflow -2

typedef int status ;
typedef  struct lnode {       //单链表的存储结构
     int  data;
     struct lnode  *next;
}lnode,*linklist ;

status initlist_l(linklist &l){      //构造一个头节点
l=new lnode;
l->next=NULL;
return ok;
 }

status getelem_l(linklist l,int i,int &e){//在带头结点的单链表l中查找第i个元素(按序号查找)
int j;
lnode *p;
p=l->next;
j=1;
while(p&&j<i){
p=p->next;
++j;
   }
if(!p||j>i)return error;
e=p->data;
return ok ;
 }

status listinsert_l(linklist &l,int i,int e){//在带头节点的单链表中第i个位置插入元素e
lnode *p ,*s;
p=l;
int j=0;
while(p&&j<i-1){
        p=p->next;
++j;
}
 if(!p||j>i-1)return error;
s=new lnode ;
s->data=e;
s->next=p->next;
p->next=s;
return ok;
 }

//单链表的删除
status listdetele_l(linklist &l,int i,int &e){
   lnode *p ,*q;
   p=l;
   int j=0;
   while(p->next&&j<i-1){
          p=p->next;
++j;
}
   if(!(p->next)||j>i-1)return error;
q=p->next;
p->next=q->next;
e=q->data ;
delete q;
return ok;
 }

 //前插法创建单链表
void createlist_f(linklist &l,int n){
lnode *p ;
int i;
l=new lnode;
l->next=0;
for(i=n;i>0;--i){
p=new lnode;     scanf("%d",&p->data );
p->next=l->next;
l->next=p;
}
}

void main(){
  linklist  l;
  lnode *p;
  int e;
  int k,h;
  //h=initlist_l(l);
createlist_f(l, 9);     
  p=l->next;
while(p) {
printf("%d ",p->data);
p=p->next;
}
printf("\n");
 
listinsert_l( l, 4, 999);
p=l->next;
while(p){
printf("%d ",p->data);
p=p->next;
}
   printf("\n");
listdetele_l(l, 7, e);
p=l->next;
while(p){
printf("%d ",p->data);
p=p->next;
}
printf("\n");
 }

D:\ffaf\ffaf.c(12) : error C2143: syntax error : missing ')' before '&'
D:\ffaf\ffaf.c(12) : error C2143: syntax error : missing '{' before '&'
D:\ffaf\ffaf.c(12) : error C2059: syntax error : '&'
D:\ffaf\ffaf.c(12) : error C2059: syntax error : ')'
D:\ffaf\ffaf.c(18) : error C2143: syntax error : missing ')' before '&'
D:\ffaf\ffaf.c(18) : error C2143: syntax error : missing '{' before '&'
D:\ffaf\ffaf.c(18) : error C2059: syntax error : '&'
D:\ffaf\ffaf.c(18) : error C2059: syntax error : ')'
D:\ffaf\ffaf.c(32) : error C2143: syntax error : missing ')' before '&'
D:\ffaf\ffaf.c(32) : error C2143: syntax error : missing '{' before '&'
D:\ffaf\ffaf.c(32) : error C2059: syntax error : '&'
D:\ffaf\ffaf.c(32) : error C2059: syntax error : ')'
D:\ffaf\ffaf.c(49) : error C2143: syntax error : missing ')' before '&'
D:\ffaf\ffaf.c(49) : error C2143: syntax error : missing '{' before '&'
D:\ffaf\ffaf.c(49) : error C2059: syntax error : '&'
D:\ffaf\ffaf.c(49) : error C2059: syntax error : ')'
D:\ffaf\ffaf.c(66) : error C2143: syntax error : missing ')' before '&'
D:\ffaf\ffaf.c(66) : error C2143: syntax error : missing '{' before '&'
D:\ffaf\ffaf.c(66) : error C2059: syntax error : '&'
D:\ffaf\ffaf.c(66) : error C2059: syntax error : ')'
D:\ffaf\ffaf.c(84) : warning C4013: 'createlist_f' undefined; assuming extern returning int
D:\ffaf\ffaf.c(92) : warning C4013: 'listinsert_l' undefined; assuming extern returning int
D:\ffaf\ffaf.c(99) : warning C4013: 'listdetele_l' undefined; assuming extern returning int
Error executing cl.exe.

ffaf.obj - 20 error(s), 3 warning(s)
搜索更多相关主题的帖子: include return status 元素 
2013-10-28 22:41
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:10 
c语言里&是运算符,不能用在函数定义上。

总有那身价贱的人给作业贴回复完整的代码
2013-10-29 05:47
heroinearth
Rank: 10Rank: 10Rank: 10
来 自:云南曲靖
等 级:青峰侠
帖 子:430
专家分:1506
注 册:2011-10-24
收藏
得分:7 
c语言中好象没有new
2013-10-29 09:09
快速回复:一个单链表操作,错误好多啊,是不是少了什么头文件?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020597 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved