-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.c
62 lines (50 loc) · 1.31 KB
/
list.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
#include <stdio.h> //for printf
#include <stdlib.h> //for exit
#include "list.h"
void INITIALIZE_list (int length, struct List *list)
{
(*list).pointer = (int *) malloc (length * sizeof(int));
(*list).position = 0;
for (int i = 0; i < length; i++)
(*list).pointer[i]=0;
}
void ADD_list (int item, struct List *list)
{
(*list).pointer[(*list).position] = item;
(*list).position++;
}
void PRINT_list (struct List *list)
{
for (int i = 0; i < (*list).position ; i++)
{
int num = (*list).pointer[i];
if (num >= 1 && num <= 15) printf("L%02d ", num);
if (num >= 16 && num <= 30) printf("I%02d ", num);
if (num >= 31 && num <= 45) printf("N%02d ", num);
if (num >= 46 && num <= 60) printf("U%02d ", num);
if (num >= 61 && num <= 75) printf("X%02d ", num);
}
printf("\n\n");
}
int CHECK_list (int item, struct List *list)
{
for (int i = 0; i < (*list).position ; i++)
{
if ( (*list).pointer[i] == item)
return 1;
}
return 0;
}
long RANDOM (struct List *list)
{
long num;
int duplicate = 0;
while (duplicate == 0)
{
num = (rand() % 75) + 1;
if (CHECK_list (num, list) == 1) duplicate = 1;
if (duplicate == 0) break;
duplicate = 0;
}
return num;
}