Commit 253537f 1 parent 3204145 commit 253537f Copy full SHA for 253537f
File tree 2 files changed +14
-11
lines changed
2 files changed +14
-11
lines changed Original file line number Diff line number Diff line change 12
12
13
13
#include < string.h>
14
14
#include < ctype.h>
15
- int insert (int set[], int n);
15
+ void insert (int set[], int n);
16
16
void print_set (int set[]);
17
17
void print_intersection (int seta[], int setb[]);
18
18
19
- int insert (int set[], int n) {
20
- set[0 ]++;
21
- int len=set[0 ], i=1 ;
22
- for (i=1 ; i<len; i++) {
23
- if (set[i] > n) break ;
24
- if (set[i] == n) { set[0 ]--; return 0 ; }
19
+ /* Insert a number into the set, if it isn't already there. */
20
+ /* Minor optimization: start at the end of the array since it is sorted. */
21
+ void insert (int set[], int n) {
22
+ int i, len=set[0 ];
23
+ for (i=len; i>0 ; i--) {
24
+ if (set[i] == n) return ;
25
+ if (set[i] < n) break ;
25
26
}
26
- memmove (set+i+1 , set+i, (len-i)*sizeof (set[0 ]));
27
+ i++;
28
+ memmove (set+i+1 , set+i, len*sizeof (set[0 ]));
27
29
set[i] = n;
30
+ set[0 ]++;
28
31
}
29
32
30
33
/* Define states that simply copy text instead of lexing */
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ LINERANGE {LINENUM}?[ \t]*-[ \t]*{LINENUM}?
37
37
int parse_linelist (char *);
38
38
int parse_linerange (char *);
39
39
int parse_erl (char *);
40
- int insert (int set[], int n);
40
+ void insert (int set[], int n);
41
41
void print_set (int set[]);
42
42
void print_intersection (int seta[], int setb[]);
43
43
@@ -50,10 +50,10 @@ LINERANGE {LINENUM}?[ \t]*-[ \t]*{LINENUM}?
50
50
51
51
/* Insert a number into the set, if it isn't already there. */
52
52
/* Minor optimization: start at the end of the array since it is sorted. */
53
- int insert (int set[], int n) {
53
+ void insert (int set[], int n) {
54
54
int i, len=set[0 ];
55
55
for (i=len; i>0 ; i--) {
56
- if (set[i] == n) return 0 ;
56
+ if (set[i] == n) return ;
57
57
if (set[i] < n) break ;
58
58
}
59
59
i++;
You can’t perform that action at this time.
0 commit comments