-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstance.c
More file actions
44 lines (39 loc) · 1.26 KB
/
Copy pathInstance.c
File metadata and controls
44 lines (39 loc) · 1.26 KB
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
#include "Instance.h"
Instance_t *InstanceConstruct(Attribute_t *attribute, Classification_t *classification)
{
Instance_t *newInstance = (Instance_t *)malloc(sizeof(Instance_t));
if(newInstance == NULL)
{
printf("Not enough memory");
exit(0);
}
newInstance->attribute = attribute;
newInstance->classification = classification;
newInstance->next = NULL;
return newInstance;
}
Instance_t *addInstance(Instance_t **startInstance, Instance_t *lastInstance, Attribute_t *attribute, Classification_t *classification)
{
if(*startInstance == NULL)
{
*startInstance = InstanceConstruct(attribute, classification);
return *startInstance;
}
lastInstance->next = InstanceConstruct(attribute, classification);
return lastInstance->next;
}
void printInstance(Instance_t *startInstance)
{
printf("INSTANCES\n\n");
Instance_t *currentInstance = startInstance;
int instanceIndex = 0;
while(currentInstance != NULL)
{
printf("Instance %d: ",instanceIndex);
printAttribute(currentInstance->attribute);
printf("%s\n", currentInstance->classification->classificationName);
currentInstance = currentInstance->next;
instanceIndex++;
}
printf("\n");
}