-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean.h
110 lines (96 loc) · 1.85 KB
/
clean.h
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
/**
*** functions are FREENODE CLEARVAL CLEAN and struct sysCPS getNNode
* stage1
**/
void freeNode(struct sysCPS *headRef) {
struct sysCPS *tmp=headRef;
printf("\ndfdsfdf\n");
while(tmp) {
headRef = headRef->next;
free(tmp);
tmp = headRef;
}
}
void clear_val() {
int i=0, j=0;
for(i=0; i<5000; i++) {
for(j=0; j<5000; j++) {
if((i == 0) || (j == 0)) {
val[i][j] = 0;
}
else {
val[i][j] = -1;
}
}
}
}
struct sysCPS *getNNode(int n, struct sysCPS *headRef) {
struct sysCPS *tmp = headRef;
while(n) {
if(!tmp) {
return NULL;
}
n--;
tmp = tmp->next;
}
return tmp;
}
void clean() {
if(head == NULL) {
return;
}
struct sysCPS *tmp, *tmpH, *prev, *tmpT;
int countT=2, i=0;
// for one term repatition
while(1) {
if(strcmp(head->call1, head->call2) == 0) {
head = head->next;
continue;
}
break;
}
tmp = head;
while(tmp->next) {
if(strcmp((tmp->next)->call1, (tmp->next)->call2) == 0) {
tmp->next = (tmp->next)->next;
continue;
}
tmp = tmp->next;
}
// for generalizing more than one term repatition
while(countT <= (lengthPoset(head)/2)) {
tmpH = head;
prev = NULL;
tmp = NULL;
tmpT = NULL;
while((tmp=getNNode(countT, tmpH)) != NULL) {
for(i=0; i<(countT-1); i++) {
tmpT = getNNode(i, tmpH);
if((!tmpT) || (!tmp)) {
break;
}
if((strcmp(tmpT->call1, tmp->call1) == 0) && (strcmp(tmpT->call2, tmp->call2) == 0)) {
tmp = tmp->next;
}
else {
break;
}
}
if(i == (countT-1)) {
if(tmpH == head) {
head = getNNode(countT, head);
tmpH = head;
}
else {
prev->next = getNNode(countT, tmpH);
tmpH = prev->next;
}
}
else {
prev = tmpH;
tmpH = tmpH->next;
}
}
countT++;
}
}