blob: f7c4b1dc9e997e2f440cc5a6f896f19b279b4151 (
plain) (
blame)
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
|
#include <stdlib.h>
#include "graph.h"
struct vertexList *vertexAlloc(size_t length) {
struct vertexList *vertices = malloc(sizeof(*vertices) * length);
for(size_t i = 0; i < length; i++) {
vertices[i].first = NULL;
vertices[i].last = NULL;
}
return vertices;
}
void vertexAdd(
struct vertexList *list, size_t toWhich, size_t whichOne
) {
struct vertex *new = malloc(sizeof(*new));
new->number = whichOne;
new->next = NULL;
if(list[toWhich].first == NULL) {
list[toWhich].first = new;
list[toWhich].last = new;
return;
}
list[toWhich].last->next = new;
list[toWhich].last = new;
}
|