1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct element {    
    int    value;    
    struct element* link;
} element;
element* Create();
element* Add(element* head, int n);
bool Search(element* head, int n);
element* _Union(element* a, element* b);
element* Difference(element* a, element* b);
bool IsEmpty(element* head);
void Display(element* a);
 
int main(void) {
    int num = 1;
    element* head_A = Create();
    element* head_B = Create();
 
    while (num) {
        printf("집합 A에 추가할 원소를 입력해주세요. 0을 입력하면 입력 종료 : ");
        scanf_s("%d"&num);
        Add(head_A, num);
    }
 
    Display(head_A);
}
 
 
 
 
element* Create()
{
    return NULL;
}
 
element* Add(element* head, int n)
{
    element* q = (element*)malloc(sizeof(element));
    q->value = n;
    q->link = NULL;
    if (head == NULL) {
        return q;
    }
    else {
        q->link = head;
        head = q;
        return head;
    }
 
}
 
bool Search(element* head, int n) {
    element* space = (element*)malloc(sizeof(element));
 
    while(space != NULL) {
        if (space->value == n) {
            printf("T\n"); 
            return true;
        }
        space = space->link;
    }
    free(space);
    printf("F\n");
    return false;
}
 
element* _Union(element* a, element* b)
{
    element* c = a;
    element* space = (element*)malloc(sizeof(element));
    space = b;
 
    while (space != NULL)
    {
        if (!Search(a, space->value))
            c = Add(c, space->value);
 
        space = space->link;
    }
    free(space);
    return c;
}
 
element* Difference(element* a, element* b)
{
    element* c = Create();
    element* space = (element*)malloc(sizeof(element));
    space = b;
    int flag = 0;
 
    while (a != NULL)
    {
        if (!Search(space, a->value))
            c = Add(c, a->value);
 
        a = a->link;
    }
    free(space);
    return c;
}
 
bool IsEmpty(element* head)
{
 
    if (head == NULL)
    {
        printf("T\n");
        return true;
    }
    else
    {
        printf("F\n");
        return false;
    }
}
 
void Display(element* a)
{
    element* space = (element*)malloc(sizeof(element));
    space = a;
 
    if (space == NULL)
        printf("공집합입니다.\n");
 
    else
    {
        while (space->link != NULL)
        {
            printf("%d, ", space->value);
            space = space->link;
        }
    }
 
    free(space);
}
 
 
cs

하 도대체 어디가 문제인걸까요 ?