Skip to content

Commit

Permalink
Some DFS in action.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwasham committed Jul 30, 2016
1 parent 4b979d8 commit b574ead
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ add_subdirectory(priority_queue)
add_subdirectory(splay_tree)
add_subdirectory(merge_sort)
add_subdirectory(quick_sort)
add_subdirectory(graphs)
6 changes: 6 additions & 0 deletions graphs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.5)
project(graphs_proj)

set(SOURCE_FILES main.c graphs.c)
add_executable(graphs ${SOURCE_FILES})

22 changes: 22 additions & 0 deletions graphs/graphs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "graphs.h"

UndirectedGraph * ugraph_create(int v) {
UndirectedGraph * g = malloc(sizeof(UndirectedGraph) + sizeof(struct neighbor *) * v);
assert(g);

g->v = v;
g->e = 0;

for (int i = 0; i < v; ++i) {
g->adjacency_list[i] = malloc(sizeof(struct neighbors));
assert(g->adjacency_list[i]);

g->adjacency_list[i]->length = 0;
}

return g;
}

void ugraph_destroy(UndirectedGraph* g) {

}
22 changes: 22 additions & 0 deletions graphs/graphs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <assert.h>
#include <stdlib.h>

#ifndef PROJECT_GRAPHS_H
#define PROJECT_GRAPHS_H

typedef struct {
int v; /* vertex count */
int e; /* edge count */

struct neighbors {
int length;
int list[];
} * adjacency_list[];

} UndirectedGraph;

UndirectedGraph* ugraph_create(int v);

void ugraph_destroy(UndirectedGraph* g);

#endif // PROJECT_GRAPHS_H
8 changes: 8 additions & 0 deletions graphs/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>
#include "graphs.h"

int main(int argc, char* argv[]) {
printf("Hello\n");

return 0;
}
9 changes: 9 additions & 0 deletions valgrind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

if [ $1 = "C" ]
then
/usr/bin/clang -ggdb main.c -std=c99 -Wall -Werror -o program && /usr/local/bin/valgrind ./program
elif [ $1 = "Cpp" ]
then
/usr/bin/clang++ -std=c++11 -stdlib=libc++ main.cc -Wall -Werror -o program && /usr/local/bin/valgrind ./program
fi

0 comments on commit b574ead

Please sign in to comment.