合并单链表出现的问题
来源:互联网 发布:数据库开发培训机构 编辑:程序博客网 时间:2024/06/05 18:21
今天做了一下书上的作业,但是函数运行完之后,总是提示:访问的 内存出错,源代码如下,各位大虾看下,帮我解释下吧
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node*next;
};
struct node*creat();/*创建单链表*/
struct node*concentrate(struct node*i,struct node*j);/*合并单链表*/
void print(struct node*head);/*偏历单链表*/
int main()
{
struct node*first,*second,*third;
first=creat();
second=creat();
third=concentrate(first,second);
print(third);
system("pause");
return 0;
}
struct node*creat()
{
struct node*head,*ne,*tail;
int n;
scanf("%d",&n);
head=NULL;
while(n!=-1){
ne=(struct node*)malloc(sizeof(struct node));
ne->data=n;
ne->next=NULL;
if(head==NULL)
head=ne;
else
tail->next=ne;
tail=ne;
scanf("%d",&n);
}
return(head);
}
struct node*concentrate(struct node*i,struct node*j)
{
struct node*p;
p=i;
while(i!=NULL){
i=i->next;
}
if(i->next==NULL) i->next=j;
return(p);
}
void print(struct node*head)
{
struct node*p;
p=head;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}
- 合并单链表出现的问题
- unity合并网格中出现的问题
- python合并单元格出现问题
- excel单元格合并后跨页出现的边框问题?
- POI合并单元格出现边框不完整的问题
- 多人合作合并代码时常出现的问题
- eclipse svn 创建分支与合并,出现的问题
- pdf的合并问题
- svn 合并的问题
- 两个单链表合并问题
- 多个so库合并到一起,出现问题,解决办法
- 两个list合并的问题
- 有关合并日志的问题
- 两个list合并的问题
- SQL合并时间段的问题
- Jtable单元格合并的问题
- 在论坛中出现的比较难的sql问题:18(字符合并 整数解析星期几)
- 在论坛中出现的比较难的sql问题:26(动态行专列+合并字符串、补足行数)
- Tree和Menu的数据绑定
- 解决vs2008中包含wlanapi.h头文件后编译不能通过的问题
- MFC_CFile类
- easysize_动态调整对话框控件位置和大小
- 什么是人生哪
- 合并单链表出现的问题
- Excel.dll 导出Excel控制
- JAVA 导入导出Excel
- CTrueColorToolBar
- Sharding
- 将html代码确析成json数据格式
- 构建 Lua、LuaBind 的 C++ 编译环境
- float 进行传送
- 查找BADI的方法