-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsymbol.c
69 lines (56 loc) · 822 Bytes
/
symbol.c
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "symbol.h"
int subtractSymbol(Symbol **s1, Symbol *s2)
{
Symbol *pre, *p;
if (!s2)
return 0;
if (strcmp((*s1)->name, s2->name) == 0)
{
p = *s1;
*s1 = (*s1)->next;
free(p);
return 1;
}
else
{
pre = *s1;
p = (*s1)->next;
while (p)
{
if (strcmp(p->name, s2->name) == 0)
{
pre->next = p->next;
free(p);
return 1;
}
pre = p;
p = p->next;
}
}
return 0;
}
void mergeSymbol(Symbol **s1, Symbol *s2)
{
Symbol *p;
while (s2)
{
p = *s1;
while (p)
{
if (strcmp(p->name, s2->name) == 0)
break;
p = p->next;
}
if (!p) /*在s1中没有找到*/
{
p = (Symbol *)malloc(sizeof(Symbol));
strcpy(p->name, s2->name);
p->next = *s1;
*s1 = p;
}
s2 = s2->next;
}
}