Implement these next:
// Copy one node s, giving the copy a NULL next pointer.
struct node *copy_one(struct node *s);
// Add the given node s to an existing list.
void add(struct node *s, struct node **existing);
These are useful for many purposes, but here you'll be composing them:
add(copy_one(s), &existing_list);
to build up your result.
Now the algorithm for intersection is:
set result empty
for all elements e in s1
if e->val is contained in s2
add a copy of e to result
For difference s1 - s2
, it's
set result empty
for all elements e in s1
if e is _not_ contained in s2
add a copy of e to result
I will let you work out the C. There's no fun in me giving you a complete answer.
Note that the choice of linked lists to represent sets is fine for learning about C and linked lists, but not often the best choice because it leads to slow performance for big sets.