| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 335 人关注过本帖
标题:这段里面,为啥我改了下删除函数就不能用了???
只看楼主 加入收藏
fleksin
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-7-10
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
这段里面,为啥我改了下删除函数就不能用了???
下面是原本正确程序的一部分:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define maxlen 20

struct student
{
    int num;
    char name[10];
    int age;
    char address[20];
};

typedef struct student elementtype;


struct nodelist
{
    struct nodelist *next;
    elementtype data;
};

typedef struct nodelist node;

node *initial_node()
{
    node *L;
    L=(node *)malloc(sizeof(node));
    L->next=NULL;
    return L;
}
//添加
node *nodeadd(node *L, elementtype x)
{
    node *S, *P = L;
    int k = 0;
    S=(node*)malloc(sizeof(node));
    S->data=x;
    S->next=P->next;
    P->next=S;
    return P;
}
//删除
node *nodedel(node *L, elementtype x)
{
    node *S, *P = L;
    int k = 0;
    while( (P->next != NULL) && (P->next->data.num != x.num))
        P = P->next;
    if (P != NULL)
    {

        S = P->next;
        P->next = S->next;
        free(S);
    }
    return P->next;
}

然后我把删除功能部分的程序改成下面这样后,就无法实现删除功能了,这是为什么??
//删除
node *nodedel(node *L, char n[20]) //elementtype x
{
    node *S, *P = L;
    int k = 0;
    while( (P->next != NULL) && (P->next->data.name != n ))  // x.num
        P = P->next;
    if (P != NULL)
    {

        S = P->next;
        P->next = S->next;
        free(S);
    }
    return P->next;
}
搜索更多相关主题的帖子: 删除 函数 
2010-07-25 13:54
a151937404
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:46
专家分:117
注 册:2010-6-11
收藏
得分:14 
node *nodedel(node *L, elementtype x)
楼主看到没,第二个参数是elementtype 类型的,你把它改为字符数组,调用这个函数的时候虽然两个函数名一样,但参数不一样啊,操作系统还是不会调用它的,修改后原先有用的函数没了,你修改的函数又没调用过。
2010-07-25 16:45
fleksin
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-7-10
收藏
得分:0 
回复 2楼 a151937404
如果想改成只输入一个字符n 就可以查询该怎么改
2010-07-28 09:32
快速回复:这段里面,为啥我改了下删除函数就不能用了???
数据加载中...
 
   



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

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