c语言删除表中元素,线性表a中删除线性表b中出现的元素的c语言算法

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

ooujfe

2014.02.08

dcebd7a0de6265b6ccae5ead692f1eab.png

采纳率:53%    等级:12

已帮助:40324人

#include "windows.h"

#include "stdio.h"

#include "stdlib.h"

#include "time.h"

struct Node

{

int num;

struct Node *next;

};

struct Node *CreateLink(int n)

{

int i=0;

struct Node *head, *p;

head = (struct Node *)malloc(sizeof(struct Node));

head->num=0;

head->next=NULL;

srand((unsigned)time(NULL));

for (i=0; i

{

p = (struct Node *)malloc(sizeof(struct Node));

p->num = rand()%100;

p->next = head->next;

head->next = p;

}

return head;

}

void PrintLink(struct Node *head)

{

struct Node *p=head->next;

printf("\n");

while (p != NULL)

{

printf("%d ",p->num);

p = p->next;

}

}

struct Node *DeleteLink(struct Node *h, int num)

{

struct Node *head = h, *p,*q;

p = head;

while (p->next != NULL)

{

if (p->next->num == num)

{

q = p->next;

p->next = q->next;

free(q);

}

p = p->next;

if (p == NULL)

{

break;

}

}

return head;

}

struct Node *DeleteSameNum(struct Node *h1,struct Node *h2)

{

struct Node *p,*head1=h1;

p = h2->next;

while (p != NULL)

{

head1 = DeleteLink(head1, p->num);

p = p->next;

}

return head1;

}

int main()

{

struct Node *head1, *head2;

head1 = CreateLink(20);

PrintLink(head1);

Sleep(1000);

head2 = CreateLink(20);

PrintLink(head2);

head1 = DeleteSameNum(head1,head2);

printf("\n删除相同数据后:");

PrintLink(head1);

printf("\n");

return 0;

}

00分享举报

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值