-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphAdjacenyList.h
66 lines (57 loc) · 1.38 KB
/
GraphAdjacenyList.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
struct Node{
int data;
struct Node *next;
}*List[101];
const int Size = 101;
struct Node *CreatingNewNode(int data){
struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
newNode -> data = data;
newNode -> next = NULL;
return newNode;
}
struct Node* Insert(struct Node* node, int key)
{
if (node == NULL){
return CreatingNewNode(key);;
}
Insert(node->next,key);
return node;
}
void AddRelation(int mem1, int mem2){
List[mem1-1] = Insert(List[mem1-1],mem2);
}
void RemoveRelation(int mem1,int mem2){
struct Node *newNode = List[mem1-1];
if (mem1 == 1){
List[mem1-1] = newNode -> next;
free(newNode);
return;
}
for(int i =0; i < mem2-2; i++)
newNode = newNode -> next;
struct Node* newNode2 = newNode -> next;
newNode -> next = newNode2 -> next;
free(newNode2);
}
void ViewData(){
struct Node *newNode;
for(int i = 0; i<Size; i++){
newNode = List[i];
while(newNode != NULL){
printf("%d has relation with %d\n",i+1,newNode -> data);
newNode = newNode -> next;
}
}
}
void Details(){
}
bool Search(int mem1,int mem2){
struct Node *newNode;
newNode = List[mem1-1];
while(newNode != NULL){
if(newNode -> data == mem2)
return true;
newNode = newNode -> next;
}
return false;
}