| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 490 人关注过本帖
标题:单链表的建立插入删除查找哪位大神帮忙看下这个程序哪里错了
只看楼主 加入收藏
winner1995
Rank: 2
等 级:论坛游民
帖 子:64
专家分:41
注 册:2015-10-11
结帖率:88.89%
收藏
已结贴  问题点数:20 回复次数:6 
单链表的建立插入删除查找哪位大神帮忙看下这个程序哪里错了
#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
int n;
typedef struct lnode{
    int data;
    struct lnode * next;
}lnode, * linklist;
linklist p;
void createlist(linklist L)
{cout<<"plese enter you hope data'number:"<<endl;
cin>>n;
int i;
L=(linklist)malloc(sizeof(lnode));
L->next=NULL;
cout<<"please enter your data:"<<"\f";
for(i=n;i>0;--i)
{p=(linklist)malloc(sizeof(lnode));
cin>>p->data;
p->next=L->next;
L->next=p;
}
cout<<"your linklist is:"<<"\f";
for(i=n;i>0;--i)
{cout<<p->data<<"\f";
p=p->next;
}
}
void getlist(linklist L)
{int i,j;
p=L->next;
j=1;
cout<<"please enter your searching'place:"<<"\f";
cin>>i;
while(p&&j<i)
{p=p->next;
++j;
}
if(!p||j>i)
cout<<"the i don't exist";
cout<<"your searching is:"<<"\f";
cout<<p->data;
}
void listinsert(linklist L)
{int i,j,e;
linklist s;
p=L;
j=0;
cout<<"please enter want before which insert:"<<endl;
cin>>i;
cout<<"please enter inserting'number:";
cin>>e;
while(p&&j<i-1)
{p=p->next;
++j;}
if(!p||j>i-1)
cout<<"i is error"<<endl;
s=(linklist)malloc(sizeof(lnode));
s->data=e;
s->next=p->next;
p->next=s;
cout<<"now the linklist is:"<<"\f";
for(i=n=1;i>0;--i)
{cout<<p->data<<"\f";
p=p->next;}
}
void listdelete(linklist L)
{int i,j;
linklist q;
p=L;
j=0;
cout<<"enter you want delete's xuhao:"<<"\f";
cin>>i;
while(p->next&&j<i-1)
{p=p->next;
++j;
}
if(!(p->next)||j>i-1)
cout<<"i is error"<<endl;
{q=p->next;
p->next=q->next;
free(q);
cout<<"deleting finish";}
cout<<"now the linklist is:"<<"\f";
for(i=n;i>0;--i)
{cout<<p->data<<"\f";
p=p->next;
}
cout<<endl;
}
int mian()
{
    linklist L1;
    createlist(L1);
    getlist(L1);
    listinsert(L1);
    listdelete(L1);
    return 0;
}
搜索更多相关主题的帖子: include please number 
2015-10-18 20:13
a1925212437
Rank: 2
等 级:论坛游民
帖 子:4
专家分:30
注 册:2015-10-18
收藏
得分:0 
报的什么错
2015-10-18 20:33
winner1995
Rank: 2
等 级:论坛游民
帖 子:64
专家分:41
注 册:2015-10-11
收藏
得分:0 
回复 2楼 a1925212437
-------------------Configuration: lianbiao - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/lianbiao.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

lianbiao.exe - 1 error(s), 0 warning(s)

唯望君安~
2015-10-18 20:40
a1925212437
Rank: 2
等 级:论坛游民
帖 子:4
专家分:30
注 册:2015-10-18
收藏
得分:18 
程序代码:
#include<stdio.h>
#include<stdlib.h>
int n;
typedef struct lnode{
    int data;
    struct lnode * next;
}lnode, * linklist;
linklist p;
struct lnode* createlist(linklist L)
{printf("plese enter you hope data'number:\n");
scanf("%d",&n);
int i;
L=(linklist)malloc(sizeof(lnode));
L->next=NULL;
printf("please enter your data:\n");
for(i=n;i>0;--i)
{p=(linklist)malloc(sizeof(lnode));
scanf("%d",&p->data);
p->next=L->next;
L->next=p;
}
printf("your linklist is:\n");
for(i=n;i>0;--i)
{printf("%d\n",p->data);
p=p->next;
}
return L;
}
void getlist(linklist L)
{

int i,j;

p=L->next;

j=1;
printf("please enter your searching'place:\n");
scanf("%d",&i);
while(p&&j<i)
{p=p->next;
++j;
}
if(!p||j>i)
printf("the i don't exist\n");
printf("your searching is:\n");
printf("%d\n",p->data);
}
void listinsert(linklist L)
{int i,j,e;
linklist s;
p=L;
j=0;
printf("please enter want before which insert:\n");
scanf("%d",&i);
printf("please enter inserting'number:\n");
scanf("%d",&e);
while(p&&j<i-1)
{p=p->next;
++j;}
if(!p||j>i-1)
printf("i is error");
s=(linklist)malloc(sizeof(lnode));
s->data=e;
s->next=p->next;
p->next=s;
printf("now the linklist is:\n");
for(i=n+1;i>0;--i)
{printf("%d\n",p->data);
p=p->next;}
}
void listdelete(linklist L)
{int i,j;
linklist q;
p=L;
j=0;
printf("enter you want delete's xuhao:\n");
scanf("%d",&i);
while(p->next&&j<i-1)
{p=p->next;
++j;
}
if(!(p->next)||j>i-1)
printf("i is error\n");
{q=p->next;
p->next=q->next;
free(q);
printf("deleting finish\n");}
printf("now the linklist is:\n");
for(i=n;i>0;--i)
{printf("%d",p->data);
p=p->next;
}
printf("\n");
}
int main()
{
    linklist L1;
    linklist L2=createlist(L1);
    getlist(L2);
    listinsert(L2);
    listdelete(L2);
    return 0;
}
2015-10-18 23:16
winner1995
Rank: 2
等 级:论坛游民
帖 子:64
专家分:41
注 册:2015-10-11
收藏
得分:0 
回复 4楼 a1925212437
运行出来了   多谢大神

唯望君安~
2015-10-19 16:47
winner1995
Rank: 2
等 级:论坛游民
帖 子:64
专家分:41
注 册:2015-10-11
收藏
得分:0 
回复 4楼 a1925212437
换成c++就运行不出来了  真是怪了

唯望君安~
2015-10-19 17:28
a1925212437
Rank: 2
等 级:论坛游民
帖 子:4
专家分:30
注 册:2015-10-18
收藏
得分:2 
你把printf scanf 换成cout cin 再加上iostream这个头文件试试
我改这些是因为我的编译器不能使用这个头文件和cout cin
2015-10-19 17:33
快速回复:单链表的建立插入删除查找哪位大神帮忙看下这个程序哪里错了
数据加载中...
 
   



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

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