#include <stdio.h>
#include <stdlib.h>
#define DataType int
#define TRUE 1
#define FALSE -1
struct Node{
DataType data;
struct Node *next;
};
typedef struct{
struct Node *node_Pointer;
int Size;
}set, *set_Pointer;
int init_Set(set_Pointer s){
s->node_Pointer = NULL;
s->Size = 0;
return TRUE;
}
int insert_Item(set_Pointer *s, const DataType item){
struct Node *p = (*s)->node_Pointer;
while(p){
if (item == p->data){
return FALSE;
}
p = p->next;
}
p = (*s)->node_Pointer;
struct Node *q = (struct Node *)malloc(sizeof(Node));
if (!q){
exit(1);
}
q->data = item;
q->next = p;
(*s)->node_Pointer = q;
++(*s)->Size;
return TRUE;
}
int remove_Item(set_Pointer *s, const int item){
if ((*s)->node_Pointer){
struct Node *p, *q;
p = q = (*s)->node_Pointer;
if (item == p->data){
(*s)->node_Pointer = p->next;
--(*s)->Size;
free(p);
return TRUE;
}
while (p){
p = p->next;
if (item == p->data){
q->next = p->next;
free(p);
--(*s)->Size;
break;
}
q = q->next;
}
return TRUE;
}
return FALSE;
}
int search_Item(const set_Pointer s, const DataType item){
if (s->node_Pointer){
unsigned int index = 1;
struct Node *p = s->node_Pointer;
while (p){
if (item == p->data){
return index;
}
++index;
p = p->next;
}
}
return FALSE;
}
int difference_Set(const set_Pointer s1, const set_Pointer s2, set_Pointer *s){
if (s1->node_Pointer && s2->node_Pointer) {
struct Node *p = s1->node_Pointer;
DataType item;
while (p){
item = p->data;
if (search_Item(s2, item) <= 0){
insert_Item(s, item);
}
p = p->next;
}
return TRUE;
}
return FALSE;
}
int show_Item(const set_Pointer s){
if (s->node_Pointer){
struct Node *p = s->node_Pointer;
printf_s("Set Size : %d\n", s->Size);
while (p){
printf_s("%d\n", p->data);
p = p->next;
}
return TRUE;
}
return FALSE;
}
int main(){
return EXIT_SUCCESS;
}