#include <stdlib.h>
#include "size.h"
/* define node type */
typedef struct node{
int data;
struct node *front,*next;
}node,*linkHead;
/* creat a list ,the argument n is the length of the list*/
void creatList(linkHead *head,int n)
{
int c=0;
linkHead p;
linkHead h=(linkHead)malloc(sizeof(node));
h->front=NULL;
h->data=n;
while(c <= n){
c++;
if(c == 1) *head=h;
else{
p=(linkHead)malloc(sizeof(node));
scanf("%d",&p->data);
h->next=p;
p->front=h;
h=p;
}
p->next=NULL;
}
}
/* output the list */
void printList(const linkHead head)
{
linkHead p=head->next;
while(p){
printf("/t%d/n",p->data);
p=p->next;
}
}
/* delete the node whose value of data equals with argument
* value, if deleting success function returns 1 and the length of the
* list is deducted by 1,else function will return 0.
*/
int delNode(linkHead *list,int value)
{
linkHead p=(*list)->next;
while(p){
if(p->data == value){
if(p->next){
p->front->next=p->next;
p->next->front=p->front;
free(p);
(*list)->data--;
return 1;
}
else {
p->front->next=NULL;
free(p);
(*list)->data--;
return 1;
}
}else p=p->next;
}
return 0;
}
/* delete all the nodes whose value of data equal in two list separately */
void delSame(linkHead *list1,linkHead *list2)
{
int array[MAX_SIZE]={0};
linkHead q=(*list2)->next;
if(!q) return;
else{
int i=0;
int j=0;
int k=0;
int temp=0;
while(q){
if(delNode(list1,q->data)){
array[i++]=q->data;
temp=(*list1)->data;
for(j=0; j<temp; j++)
delNode(list1,q->data);
q=q->next;
}
else q=q->next;
}
for(j=0;j<i;j++)
printf("/t/t%d/n",array[j]);
temp=(*list2)->data;
for(j=0;j<i;j++) {
for(k=0; k<temp; k++)
delNode(list2,array[j]);
}
}
}
/* the test */
main()
{
linkHead list1,list2;
creatList(&list1,6);
creatList(&list2,8);
delSame(&list1,&list2);
printList(list1);
printf("/n");
printList(list2);
}
#include "size.h"
/* define node type */
typedef struct node{
int data;
struct node *front,*next;
}node,*linkHead;
/* creat a list ,the argument n is the length of the list*/
void creatList(linkHead *head,int n)
{
int c=0;
linkHead p;
linkHead h=(linkHead)malloc(sizeof(node));
h->front=NULL;
h->data=n;
while(c <= n){
c++;
if(c == 1) *head=h;
else{
p=(linkHead)malloc(sizeof(node));
scanf("%d",&p->data);
h->next=p;
p->front=h;
h=p;
}
p->next=NULL;
}
}
/* output the list */
void printList(const linkHead head)
{
linkHead p=head->next;
while(p){
printf("/t%d/n",p->data);
p=p->next;
}
}
/* delete the node whose value of data equals with argument
* value, if deleting success function returns 1 and the length of the
* list is deducted by 1,else function will return 0.
*/
int delNode(linkHead *list,int value)
{
linkHead p=(*list)->next;
while(p){
if(p->data == value){
if(p->next){
p->front->next=p->next;
p->next->front=p->front;
free(p);
(*list)->data--;
return 1;
}
else {
p->front->next=NULL;
free(p);
(*list)->data--;
return 1;
}
}else p=p->next;
}
return 0;
}
/* delete all the nodes whose value of data equal in two list separately */
void delSame(linkHead *list1,linkHead *list2)
{
int array[MAX_SIZE]={0};
linkHead q=(*list2)->next;
if(!q) return;
else{
int i=0;
int j=0;
int k=0;
int temp=0;
while(q){
if(delNode(list1,q->data)){
array[i++]=q->data;
temp=(*list1)->data;
for(j=0; j<temp; j++)
delNode(list1,q->data);
q=q->next;
}
else q=q->next;
}
for(j=0;j<i;j++)
printf("/t/t%d/n",array[j]);
temp=(*list2)->data;
for(j=0;j<i;j++) {
for(k=0; k<temp; k++)
delNode(list2,array[j]);
}
}
}
/* the test */
main()
{
linkHead list1,list2;
creatList(&list1,6);
creatList(&list2,8);
delSame(&list1,&list2);
printList(list1);
printf("/n");
printList(list2);
}