Code:

#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct node{ int num; struct node *next; }Node, *NodePtr; main() { NodePtr isDeleted(NodePtr, int); NodePtr setDifference(NodePtr, NodePtr); NodePtr makeNode(int); int isMember(NodePtr, int); void printDif(NodePtr); //generation of list 1 int n; NodePtr top, np, last; top = NULL; if(scanf("%d", &n)!=1)n=0; while(n!=0) { np = makeNode(n); if(top ==NULL)top = np; else last->next = np; last = np; if(scanf("%d", &n)!=1)n=0; }//end while //generation of list 2 int m; NodePtr to, newp,las; to = NULL; if(scanf("%d", &m)!=1)m=0; while(m!=0) { newp = makeNode(m); if(to ==NULL)to = newp; else las->next = newp; las = newp; if(scanf("%d", &m)!=1)m=0; }//end while NodePtr lover = setDifference(top, to); printDif(lover); }//end main NodePtr makeNode(int n) { NodePtr np = (NodePtr)malloc(sizeof(Node)); np->num = n; np->next = NULL; return np; }//end makeNode function int isMember(NodePtr np, int z) { while(np!=NULL && z!= np->num) { np = np->next; } if(np==NULL){ return 0; }else{ return np->num; } } NodePtr isDeleted(NodePtr np, int d) { NodePtr prev, curr, temp; prev = NULL; curr = np; while(curr!= NULL && d !=curr->num){ prev = curr; curr = curr->next; } if(curr->num==d) { temp = curr; prev->next = curr->next; printf("\nNode deleted:"); free(temp); } return np; }//end isDelete NodePtr setDifference(NodePtr top, NodePtr to) { int test; while(to!=NULL){ int result = isMember(top, to->num); if(result!=100000){ top = isDeleted(top,to->num); } to = to->next; }//end setDifference return top; } void printDif(NodePtr np){ while(np!=NULL) { printf("\nThis is the print for set difference %d\n",np->num); np = np->next; }//end while }