-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrafoSt21.c
117 lines (104 loc) · 2.75 KB
/
GrafoSt21.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "rQuickSort.h"
#include "GrafoSt21.h"
typedef uint32_t u32;
//Forward declarations para que no se queje gcc
u32 Nombre(u32 i, GrafoSt *G);
u32 OrdenVecino(u32 j, u32 i, GrafoSt *G);
u32 print_graph(GrafoSt *g, u32 lines)
{
u32 M = g->num_vertices;
vertice vert;
vertice vecino;
u32 longitud_lista = 0;
if (lines > M)
return 1;
printf("-------------------------\n");
for (u32 k= 0; k < lines; k++ )
{
printf("Nombre: %d, Orden: %d\n", Nombre(k,g),k);
}
printf("-------------------------\n");
for (u32 i = 0; i < lines; i++)
{
vert = g->vertices[g->orden[i]];
printf("%u: vertice: %u c: %u -> \n", i, vert.nombre, vert.color);
printf(" vecinos:\n");
printf("( \n");
longitud_lista = vert.grado;
printf("grado: %u \n", longitud_lista);
for (u32 j = 0; j < longitud_lista; j++)
{
vecino = g->vertices[darray_get(j, vert.vecinos)];
printf("(%d >> v: %u, orden: %u, color: %u )", j, vecino.nombre, OrdenVecino(j,i,g), vecino.color);
}
printf("\n ) \n");
printf("\n");
}
return 0;
}
Lado_st parse_edge(void)
{
char buffer[80];
char *readStr;
char *token, *ptr;
Lado_st edge = {0xFFFFFFFF, 0xFFFFFFFF};
u32 a, b = 0;
readStr = buffer;
if (fgets(readStr, sizeof(buffer), stdin) == NULL)
return edge;
if (readStr[0] == 'e')
{
token = strtok(readStr, "e ");
a = (u32)strtoul(token, &ptr, 10);
token = strtok(NULL, " ");
b = (u32)strtoul(token, &ptr, 10);
edge.v = a;
edge.w = b;
}
return edge;
}
void insert_edge(u32 v_key, u32 w_key, GrafoSt *g, hash_table ht)
{
u32 v_position = ht_get(v_key, ht);
u32 w_position = ht_get(w_key, ht);
if (v_position == 0xFFFFFFFF)
{
g->vertices[ht->ocupation] = Vertice(v_key);
v_position = ht->ocupation;
ht_put(v_key, v_position, ht);
}
if (w_position == 0xFFFFFFFF)
{
g->vertices[ht->ocupation] = Vertice(w_key);
w_position = ht->ocupation;
ht_put(w_key, w_position, ht);
}
darray_push(w_position, g->vertices[v_position].vecinos);
darray_push(v_position, g->vertices[w_position].vecinos);
}
void GenerarOrdenNatural(GrafoSt *G)
{
u32 n = G->num_vertices;
u32 *a = calloc(n, sizeof(u32));
u32 *b = calloc(n, sizeof(u32));
for(u32 i = 0; i < n; ++i)
{
a[i] = Nombre(i, G);
b[i] = i;
}
quickSort(a, b, 0, n-1);
for(u32 j = 0; j<n; ++j)
{
G->orden_natural[j] = b[j];
}
free(a);
free(b);
}
u32 delta(GrafoSt *g)
{
return g->Delta;
}