-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcategorytree.c
66 lines (52 loc) · 1.31 KB
/
categorytree.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
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <assert.h>
typedef struct tCategory
{
char* RecordParent;
char* RecordName;
bool RootCategory;
struct tCategory * nextNode;
} tCategory;
bool addCategory(char* name, tCategory* parent);
bool getChildren(tCategory* category, char* results);
int main(int argc, char const *argv[])
{
/* code */
return 0;
}
bool addCategory(char* name, tCategory* parent)
{
// memory allocation
tCategory* Record = (tCategory*) malloc(sizeof(tCategory));
if(Record == NULL)
return false;
//check if parent category does not exist
//Check if category already exists
//check if it is a root category
if(parent == 'NULL')
{
Record->RootCategory=true;
Record->RecordParent = NULL;
}
else
{
Record->RootCategory=false;
Record->RecordParent=parent->RecordName;
}
parent->nextNode = (Record);
Record->RecordName = name;
Record->nextNode = NULL;
return true;
}
bool getChildren(tCategory* category, char* results)
{
while(category->nextNode != NULL)
{
//Print immediate node successor and point to it.
printf("%s -> %s", category->RecordParent, category->RecordName);
category=(category->nextNode);
}
return true;
}