-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.c
52 lines (50 loc) · 1.49 KB
/
info.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
#include <stdio.h>
#include <stdlib.h>
#include "info.h"
Queue make_info_queue( Map map, char entryVertex){
int i=0,j=0;
Queue queue;
queue.head = NULL;
queue.tail = NULL;
int found = 0;
do{
if(map.graph[j]->letter == entryVertex){
found = 1;
}
j++;
}while(j<map.size && found == 0);
Info * node = (Info*)malloc(sizeof(Info));
node->data.letter = map.graph[j-1]->letter;
node->data.distanceFromStart = 0; // zero because this is the starting node
node->data.via = '-';
node->next = NULL;
queue.head = node;
queue.tail = node;
for(i=0; i<map.size; i++){
if(map.graph[i]->letter != entryVertex){
Info * node = (Info*)malloc(sizeof(Info));
node->data.letter = map.graph[i]->letter;
node->data.distanceFromStart = 9999; // means Infinity (INF)
node->data.via = '-';
node->next = NULL;
queue.tail->next = node;
queue.tail = node;
}
}
return queue;
}
void showQueue(Queue queue){
while(queue.head != NULL){
printf("%c , %d, %c\n", queue.head->data.letter, queue.head->data.distanceFromStart, queue.head->data.via);
queue.head = queue.head->next;
}
}
/*Queue enqueue(Queue queue, Info * list, Map map){
int i=0;
Info * inf = NULL;
for(i=0; i<map.size; i++){
if(queue.head == NULL && queue.tail == NULL){
inf = (Info*)malloc(sizeof(Info));
}
}
}*/