C语言中链表问题
来源:百度知道 编辑:UC知道 时间:2024/05/25 07:49:32
写了一个程序练习链表的基本操作,包括建立链表,删除,插入,打印和查找,程序虽然可以运行,可是结果有问题,只能完成建立功能,不能完成其他几个功能,不知问题出在何处,请大家帮忙看看啊。
/*链表的基本操作*/
#include <stdio.h>
#include <stdlib.h>
/*定义链表结点*/
typedef struct node
{ int data;
struct node *link ;
}LNode;
/*函数声明*/
LNode *createtail(int m);
LNode *locatenode(LNode *p,int x);
LNode * insertlist(LNode *head,int a,int b);
int deletelist (LNode *h,int x );
void displaylist(LNode *h);
/*主函数*/
main ()
{
LNode *L;
int number,a,b,i,e,result1,result2; /*result1,result2为控制变量*/
printf("please input the node's number:");
scanf("%d",&number);
L=createtail(number);
printf("The current list is :\n");
displaylist(L);
printf("please enter a number 'a' to be inserted before 'b': a, b=:");
scanf("%d%d",&a,&b);
result1=insertlis
/*链表的基本操作*/
#include <stdio.h>
#include <stdlib.h>
/*定义链表结点*/
typedef struct node
{ int data;
struct node *link ;
}LNode;
/*函数声明*/
LNode *createtail(int m);
LNode *locatenode(LNode *p,int x);
LNode * insertlist(LNode *head,int a,int b);
int deletelist (LNode *h,int x );
void displaylist(LNode *h);
/*主函数*/
main ()
{
LNode *L;
int number,a,b,i,e,result1,result2; /*result1,result2为控制变量*/
printf("please input the node's number:");
scanf("%d",&number);
L=createtail(number);
printf("The current list is :\n");
displaylist(L);
printf("please enter a number 'a' to be inserted before 'b': a, b=:");
scanf("%d%d",&a,&b);
result1=insertlis
改好了,经过测试,应该没有问题。删除,插入两个函数有问题
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int data;
struct node *link ;
} LNode;
LNode *createtail(int m);
LNode *locatenode(LNode *p,int x);
LNode * insertlist(LNode *head,int a,int b);
int deletelist (LNode *h,int x );
void displaylist(LNode *h);
main () {
LNode *L;
int number, a, b, i, e, result1, result2;
printf ("please input the node's number:");
scanf ("%d",&number);
L = createtail(number);
printf("The current list is :\n");
displaylist(L);
printf ("please enter a number 'a' to be inserted before 'b': a, b=:");
scanf ("%d%d", &a, &b);
result1 = insertlist (L, a, b);
if(result1)
printf("Success to insert!\n");
printf("The new list is:\n"