Skip to content

Commit 4a0da70

Browse files
authored
Merge pull request #2 from kosmaroDev/feature-issue#77
Feature issue#1 (jgmarquesm/Data-Structures#77) Adicionando UWG usando linked list
2 parents dd647d2 + 395951d commit 4a0da70

File tree

25 files changed

+944
-53
lines changed

25 files changed

+944
-53
lines changed

Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ SQ = $(MAIN)/StaticQueue
1010
DQ = $(MAIN)/DynamicQueue
1111
MAT = $(MAIN)/Matrix
1212
UWG1 = $(MAIN)/UndirectedWeightedGraph1
13+
UWG2 = $(MAIN)/UndirectedWeightedGraph2
1314
#--NEW_DS_DIR
1415
EH = $(HELPERS)/ExceptionHandler
1516
N = $(HELPERS)/Node
1617
V = $(HELPERS)/Vertex
18+
E = $(HELPERS)/Edge
1719
#--NEW_HELPER_DIR
1820

1921
APP = LIBDS
@@ -40,14 +42,16 @@ ED6 = dynamic_stack
4042
ED7 = static_queue
4143
ED8 = dynamic_queue
4244
ED9 = matrix
43-
ED10 = undirected_weighted_graph_1
45+
ED10 = undirected_weighted_graph1
46+
ED11 = undirected_weighted_graph2
4447
#--ADD_NEW_DS
45-
#DS11
48+
#DS12
4649
H1 = exception_handler
4750
H2 = node
4851
H3 = vertex
52+
H4 = edge
4953
#--ADD_NEW_HELPER
50-
#H4
54+
#H5
5155

5256
# Compilation Flags
5357
FLAGS = -O3 -Wall -pedantic -Warray-bounds -Werror
@@ -75,6 +79,8 @@ LIBS = -l$(LIB_NAME) -L $(LIB)
7579
cp $(EH)/$(MAIN)/$(SRC)/$(H1).c $(APP)/$(AUX)/$(SRC)
7680
cp $(N)/$(MAIN)/$(SRC)/$(H2).c $(APP)/$(AUX)/$(SRC)
7781
cp $(V)/$(MAIN)/$(SRC)/$(H3).c $(APP)/$(AUX)/$(SRC)
82+
cp $(UWG2)/$(MAIN)/$(SRC)/$(ED11).c $(APP)/$(AUX)/$(SRC)
83+
cp $(E)/$(HELPERS)/$(SRC)/$(H4).c $(APP)/$(AUX)/$(SRC)
7884
#--GET_SRC
7985

8086
--private-get_headers:
@@ -91,6 +97,8 @@ LIBS = -l$(LIB_NAME) -L $(LIB)
9197
cp $(EH)/$(MAIN)/$(INCLUDE)/$(H1).h $(APP)/$(INCLUDE)
9298
cp $(N)/$(MAIN)/$(INCLUDE)/$(H2).h $(APP)/$(INCLUDE)
9399
cp $(V)/$(MAIN)/$(INCLUDE)/$(H3).h $(APP)/$(INCLUDE)
100+
cp $(UWG2)/$(MAIN)/$(INCLUDE)/$(ED11).h $(APP)/$(INCLUDE)
101+
cp $(E)/$(HELPERS)/$(INCLUDE)/$(H4).h $(APP)/$(INCLUDE)
94102
#--GET_H
95103

96104
--private-get_eds: --private-create_lib --private-get_srcs --private-get_headers
@@ -122,6 +130,8 @@ compile: $(APP)/$(AUX)/$(OBJ)/$(ED1).o \
122130
$(APP)/$(AUX)/$(OBJ)/$(H1).o \
123131
$(APP)/$(AUX)/$(OBJ)/$(H2).o \
124132
$(APP)/$(AUX)/$(OBJ)/$(H3).o \
133+
$(APP)/$(AUX)/$(OBJ)/$(ED11).o \
134+
$(APP)/$(AUX)/$(OBJ)/$(H4).o \
125135
#--ADD_TO_COMPILE
126136
ar -rcs $(APP)/$(LIB)/lib$(LIB_NAME).a $(APP)/$(AUX)/$(OBJ)/*.o
127137
rm -rf $(APP)/$(AUX)

main/UndirectedWeightedGraph1/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ ds_FOLDER_1 = ../Array/$(MAIN)
1717
#--ADD_FOLDER_NEW_ds
1818

1919
# Names Definition
20-
APP_NAME = app_undirected_weighted_graph_1
21-
LIB_NAME = uwg
22-
DS = undirected_weighted_graph_1
23-
TEST_DS = undirected_weighted_graph_1.test
20+
APP_NAME = app_undirected_weighted_graph1
21+
LIB_NAME = UWG1
22+
DS = undirected_weighted_graph1
23+
TEST_DS = undirected_weighted_graph1.test
2424
UNITY = ../../resources/unity
2525
DEPS = ../../resources/scripts/dependencies
2626
INSTALL = install.sh
File renamed without changes.

main/UndirectedWeightedGraph1/main/include/undirected_weighted_graph_1.h renamed to main/UndirectedWeightedGraph1/main/include/undirected_weighted_graph1.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
#define __DEFAULT_PTR__ NULL
4343
#define __TYPE_PRINT_FUNCTION_NAME__ type_print_func
4444
#define __TYPE_PRINT_FUNCTION_SIGNATURE__ void (*__TYPE_PRINT_FUNCTION_NAME__)(void *data)
45-
#define SIZE_OF_UNDIRECTED_WEIGHTED_GRAPH_1_TYPE size_of_undirected_weighted_graph_1_type
45+
#define SIZE_OF_UNDIRECTED_WEIGHTED_GRAPH1_TYPE size_of_undirected_weighted_graph1_type
4646

47-
extern const size_t size_of_undirected_weighted_graph_1_type;
47+
extern const size_t size_of_undirected_weighted_graph1_type;
4848

4949
/**
5050
* @remark
@@ -59,7 +59,7 @@ extern const size_t size_of_undirected_weighted_graph_1_type;
5959
* 3 - Type comparison function: To compare data correctly.\n
6060
* @example int (*type_compare_function)(void *data1, void *data2)
6161
*/
62-
typedef struct _undirected_weighted_graph_1 UndirectedWeightedGraph1;
62+
typedef struct _undirected_weighted_graph1 UndirectedWeightedGraph1;
6363

6464
/**
6565
*

main/UndirectedWeightedGraph1/main/src/undirected_weighted_graph_1.c renamed to main/UndirectedWeightedGraph1/main/src/undirected_weighted_graph1.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
#include "../include/matrix.h"
55
#include "../include/array.h"
66
//#--ADD_TO_INCLUDE
7-
#include "../include/undirected_weighted_graph_1.h"
7+
#include "../include/undirected_weighted_graph1.h"
88

99
void _print_adjacency(void *value) {
1010
printf("%.2f", *((float *) value));
1111
}
1212

13-
typedef struct _undirected_weighted_graph_1 {
13+
typedef struct _undirected_weighted_graph1 {
1414
long capacity;
1515
long size;
1616
Array *vertices;
1717
Matrix *adjacency_matrix;
1818
} UndirectedWeightedGraph1;
1919

20-
const size_t size_of_undirected_weighted_graph_type = sizeof(UndirectedWeightedGraph1);
20+
const size_t size_of_undirected_weighted_graph1_type = sizeof(UndirectedWeightedGraph1);
2121

2222
long _vertex_index(UndirectedWeightedGraph1 *uwg, void *data) {
2323
for (long i = 0; i < uwg->size; i++) {
@@ -86,7 +86,7 @@ UndirectedWeightedGraph1 *UndirectedWeightedGraph1_create(const long max_of_vert
8686
)
8787
) return NULL;
8888

89-
UndirectedWeightedGraph1 *uwg = (UndirectedWeightedGraph1 *) calloc(1, size_of_undirected_weighted_graph_type);
89+
UndirectedWeightedGraph1 *uwg = (UndirectedWeightedGraph1 *) calloc(1, size_of_undirected_weighted_graph1_type);
9090
uwg->capacity = max_of_vertices;
9191
uwg->size = 0;
9292

main/UndirectedWeightedGraph1/test/tests/undirected_weighted_graph_1.test.c renamed to main/UndirectedWeightedGraph1/test/tests/undirected_weighted_graph1.test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "../../main/include/unity.h"
2-
#include "../../main/include/undirected_weighted_graph_1.h"
2+
#include "../../main/include/undirected_weighted_graph1.h"
33
#include <stdio.h>
44

55
#define TYPE int
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ptd_ds_CircularDoublyLinkedList
2+
pvt_hp_Node
3+
pub_hp_ExceptionHandler
4+
ptd_hp_Edge
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Directories
2+
MAIN = main
3+
TEST = test
4+
# Generics
5+
APPS = apps
6+
TESTS = tests
7+
BIN = bin
8+
INCLUDE = include
9+
LIB = lib
10+
OBJ = obj
11+
SRC = src
12+
hp_FOLDER_0 = ../../resources/helpers/Node/$(MAIN)
13+
hp_DEP_FOLDER_0_1 = ../../resources/helpers/ExceptionHandler/$(MAIN)
14+
hp_FOLDER_1 = ../../resources/helpers/Edge/$(MAIN)
15+
#--ADD_FOLDER_NEW_hp
16+
ds_FOLDER_0 = ../CircularDoublyLinkedList/$(MAIN)
17+
#--ADD_FOLDER_NEW_ds
18+
19+
# Names Definition
20+
APP_NAME = app_undirected_weighted_graph2
21+
LIB_NAME = UWG2
22+
DS = undirected_weighted_graph2
23+
TEST_DS = undirected_weighted_graph2.test
24+
UNITY = ../../resources/unity
25+
DEPS = ../../resources/scripts/dependencies
26+
INSTALL = install.sh
27+
hp_0 = node
28+
hp_DEP_0_1 = exception_handler
29+
hp_1 = edge
30+
#--ADD_NEW_hp
31+
ds_0 = circular_doubly_linked_list
32+
#--ADD_NEW_ds
33+
#ds1
34+
#hp2
35+
36+
# Compilation Flags
37+
FLAGS = -O3 -Wall -pedantic -Warray-bounds -Werror
38+
LIBS = -l$(LIB_NAME) -L $(MAIN)/$(LIB)
39+
40+
--private-create_folders:
41+
mkdir $(MAIN)/$(LIB)
42+
mkdir $(MAIN)/$(OBJ)
43+
mkdir $(MAIN)/$(BIN)
44+
mkdir $(TEST)/$(BIN)
45+
46+
--private-get_external_lib:
47+
cp $(ds_FOLDER_0)/$(SRC)/$(ds_0).c $(MAIN)/$(SRC)/
48+
cp $(ds_FOLDER_0)/$(INCLUDE)/$(ds_0).h $(MAIN)/$(INCLUDE)/
49+
cp $(hp_FOLDER_0)/$(SRC)/$(hp_0).c $(MAIN)/$(SRC)/
50+
cp $(hp_FOLDER_0)/$(INCLUDE)/$(hp_0).h $(MAIN)/$(INCLUDE)/
51+
cp $(hp_DEP_FOLDER_0_1)/$(SRC)/$(hp_DEP_0_1).c $(MAIN)/$(SRC)/
52+
cp $(hp_DEP_FOLDER_0_1)/$(INCLUDE)/$(hp_DEP_0_1).h $(MAIN)/$(INCLUDE)/
53+
cp $(hp_FOLDER_1)/$(SRC)/$(hp_1).c $(MAIN)/$(SRC)/
54+
cp $(hp_FOLDER_1)/$(INCLUDE)/$(hp_1).h $(MAIN)/$(INCLUDE)/
55+
#--ADD_GET_NEW_LIB
56+
cp $(UNITY)/$(INCLUDE)/* $(MAIN)/$(INCLUDE)/
57+
cp $(UNITY)/$(SRC)/* $(MAIN)/$(SRC)/
58+
59+
pack: clean_all --private-create_folders --private-get_external_lib \
60+
$(MAIN)/$(OBJ)/$(DS).o \
61+
$(MAIN)/$(OBJ)/$(ds_0).o \
62+
$(MAIN)/$(OBJ)/$(hp_0).o \
63+
$(MAIN)/$(OBJ)/$(hp_DEP_0_1).o \
64+
$(MAIN)/$(OBJ)/$(hp_1).o \
65+
#--ADD_TO_PACK
66+
ar -rcs $(MAIN)/$(LIB)/lib$(LIB_NAME).a $(MAIN)/$(OBJ)/*.o
67+
68+
compile_apps: $(MAIN)/$(BIN)/$(APP_NAME)
69+
70+
compile_test: $(MAIN)/$(OBJ)/$(DS).o \
71+
$(MAIN)/$(OBJ)/unity.o \
72+
$(TEST)/$(BIN)/$(TEST_DS) \
73+
$(MAIN)/$(OBJ)/$(ds_0).o \
74+
$(MAIN)/$(OBJ)/$(hp_0).o \
75+
$(MAIN)/$(OBJ)/$(hp_DEP_0_1).o \
76+
$(MAIN)/$(OBJ)/$(hp_1).o \
77+
#--ADD_TO_COMPILE_TEST
78+
79+
run_apps: pack compile_apps
80+
$(MAIN)/$(BIN)/$(APP_NAME)
81+
make clean_external
82+
83+
run_tests: clean_all pack compile_test
84+
$(TEST)/$(BIN)/$(TEST_DS)
85+
make clean_all
86+
87+
install_ds:
88+
$(DEPS)/$(INSTALL) -ds
89+
90+
install_helper:
91+
$(DEPS)/$(INSTALL) -h
92+
93+
install:
94+
$(DEPS)/$(INSTALL) -$(filter-out $@,$(MAKECMDGOALS))
95+
96+
clean_all: clean_libs clean_apps clean_test clean_external
97+
98+
clean_libs:
99+
rm -rf $(MAIN)/$(OBJ) $(MAIN)/$(LIB)
100+
101+
clean_apps:
102+
rm -rf $(MAIN)/$(BIN)
103+
104+
clean_test:
105+
rm -rf $(TEST)/$(BIN)
106+
107+
clean_external:
108+
rm -rf $(MAIN)/$(SRC)/$(ds_0).c
109+
rm -rf $(MAIN)/$(INCLUDE)/$(ds_0).h
110+
rm -rf $(MAIN)/$(SRC)/$(hp_0).c
111+
rm -rf $(MAIN)/$(INCLUDE)/$(hp_0).h
112+
rm -rf $(MAIN)/$(SRC)/$(hp_DEP_0_1).c
113+
rm -rf $(MAIN)/$(INCLUDE)/$(hp_DEP_0_1).h
114+
rm -rf $(MAIN)/$(SRC)/$(hp_1).c
115+
rm -rf $(MAIN)/$(INCLUDE)/$(hp_1).h
116+
#--ADD_TO_CLEAN
117+
rm -rf $(MAIN)/$(SRC)/unity.c
118+
rm -rf $(MAIN)/$(INCLUDE)/unity.h
119+
rm -rf $(MAIN)/$(INCLUDE)/unity_internals.h
120+
121+
$(MAIN)/$(OBJ)/%.o: $(MAIN)/$(SRC)/%.c $(MAIN)/$(INCLUDE)/%.h
122+
gcc $(FLAGS) -c $< -I $(MAIN)/$(INCLUDE) -o $@
123+
124+
$(MAIN)/$(BIN)/%: $(MAIN)/$(APPS)/%.c
125+
gcc $(FLAGS) $< $(LIBS) -I $(MAIN)/$(INCLUDE) -o $@
126+
127+
$(TEST)/$(BIN)/%: $(TEST)/$(TESTS)/%.c
128+
gcc $(FLAGS) $< $(MAIN)/$(OBJ)/*.o -I $(MAIN)/$(INCLUDE) -o $@
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include "../include/undirected_weighted_graph2.h"
4+
5+
int main() {
6+
7+
// char *command = "make run_tests";
8+
// int executed = system(command);
9+
// if (executed != 0) return EXIT_FAILURE;
10+
11+
UndirectedWeightedGraph2 *uwg = UndirectedWeightedGraph2_create();
12+
int a = 1, b = 2, c = 3;
13+
UndirectedWeightedGraph2_insert_Vertex(uwg, &a);
14+
UndirectedWeightedGraph2_insert_Vertex(uwg, &b);
15+
UndirectedWeightedGraph2_insert_Vertex(uwg, &c);
16+
17+
UndirectedWeightedGraph2_add_Edge(uwg, 0, 1, 1.1);
18+
UndirectedWeightedGraph2_add_Edge(uwg, 0, 2, 2.2);
19+
UndirectedWeightedGraph2_add_Edge(uwg, 1, 2, 3.3);
20+
21+
float edge_0_1 = UndirectedWeightedGraph2_get_weight(uwg, 0, 1);
22+
float edge_0_2 = UndirectedWeightedGraph2_get_weight(uwg, 0, 2);
23+
float edge_1_2 = UndirectedWeightedGraph2_get_weight(uwg, 1, 2);
24+
25+
printf("Edge(0, 1): %f\n", edge_0_1);
26+
printf("Edge(0, 2): %f\n", edge_0_2);
27+
printf("Edge(1, 2): %f\n", edge_1_2);
28+
29+
int d = 4, e = 5;
30+
UndirectedWeightedGraph2_insert_Vertex(uwg, &d);
31+
UndirectedWeightedGraph2_insert_Vertex(uwg, &e);
32+
UndirectedWeightedGraph2_add_Edge(uwg, 3, 0, 4.4);
33+
UndirectedWeightedGraph2_add_Edge(uwg, 3, 1, 4.4);
34+
UndirectedWeightedGraph2_add_Edge(uwg, 3, 2, 4.4);
35+
36+
float edge_0_1_p = UndirectedWeightedGraph2_get_weight(uwg, 0, 1);
37+
float edge_0_2_p = UndirectedWeightedGraph2_get_weight(uwg, 0, 2);
38+
float edge_1_2_p = UndirectedWeightedGraph2_get_weight(uwg, 1, 2);
39+
float edge_0_3 = UndirectedWeightedGraph2_get_weight(uwg, 3, 0);
40+
float edge_1_3 = UndirectedWeightedGraph2_get_weight(uwg, 3, 1);
41+
float edge_2_3 = UndirectedWeightedGraph2_get_weight(uwg, 3, 2);
42+
43+
printf("Edge(0, 1): %f\n", edge_0_1_p);
44+
printf("Edge(0, 2): %f\n", edge_0_2_p);
45+
printf("Edge(1, 2): %f\n", edge_1_2_p);
46+
printf("Edge(0, 3): %f\n", edge_0_3);
47+
printf("Edge(1, 3): %f\n", edge_1_3);
48+
printf("Edge(2, 3): %f\n", edge_2_3);
49+
50+
UndirectedWeightedGraph2_add_Edge(uwg, 3, 2, 4.4);
51+
52+
UndirectedWeightedGraph2_set_weight(uwg, 3, 2, 99.99);
53+
float edge_2_3_p = UndirectedWeightedGraph2_get_weight(uwg, 3, 2);
54+
printf("Edge(2, 3): %f\n", edge_2_3_p);
55+
56+
float edge_0_2_p_p = UndirectedWeightedGraph2_get_weight(uwg, 2, 0);
57+
printf("Edge(0, 2): %f\n", edge_0_2_p_p);
58+
59+
UndirectedWeightedGraph2_remove_Edge(uwg, 0, 2);
60+
float edge_0_2_p_p_p = UndirectedWeightedGraph2_get_weight(uwg, 0, 2);
61+
printf("Edge(0, 2): %f\n", edge_0_2_p_p_p);
62+
63+
float edge_0_1_p_ = UndirectedWeightedGraph2_get_weight(uwg, 0, 1);
64+
float edge_0_2_p_ = UndirectedWeightedGraph2_get_weight(uwg, 0, 2);
65+
float edge_0_3_p_ = UndirectedWeightedGraph2_get_weight(uwg, 0, 3);
66+
printf("Edge(0, 1): %f\n", edge_0_1_p_);
67+
printf("Edge(0, 2): %f\n", edge_0_2_p_);
68+
printf("Edge(0, 3): %f\n", edge_0_3_p_);
69+
UndirectedWeightedGraph2_remove_Vertex(uwg, 0);
70+
float edge_0_1_p__ = UndirectedWeightedGraph2_get_weight(uwg, 0, 1);
71+
float edge_0_2_p__ = UndirectedWeightedGraph2_get_weight(uwg, 0, 2);
72+
float edge_0_3_p__ = UndirectedWeightedGraph2_get_weight(uwg, 0, 3);
73+
printf("Edge(0, 1): %f\n", edge_0_1_p__);
74+
printf("Edge(0, 2): %f\n", edge_0_2_p__);
75+
printf("Edge(0, 3): %f\n", edge_0_3_p__);
76+
77+
return EXIT_SUCCESS;
78+
}

0 commit comments

Comments
 (0)