标题:链表求集合差集问题!!!
只看楼主
asd795462
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-12-28
得分:0 
struct linknode *subs(struct linknode *ha,struct linknode *hb)
{
    struct linknode *head=NULL,*p,*q;
    int a,flag;
    p = ha;
    //*********创建新链表所用变量*********
    int i=1;
    struct linknode *t,*s;
    //************************************
    while(p != NULL){
        flag = 0; //用于表示hb里面是否有等于该节点的值
        a = p->data;
        q = hb;
        while(q != NULL){
            if(q->data == a){
                flag = 1;
                break;
            }
            q = q->next;
        }
        if(flag == 0){  //hb里面没有该值,所以将a保存入新的链表
            if(i==1){
                head = (struct linknode*)malloc(sizeof(struct linknode));
                head->data = a;
                head->next = NULL;
                t = head;
            }
            else{
                s = (struct linknode*)malloc(sizeof(struct linknode));
                s->data = a;
                s->next = NULL;
                t->next = s;
                t = s;
            }
            i++;  //别漏了
        }
        p = p->next;
    }
    return head;
}
2014-09-09 14:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-321259-1-1.html




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

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