forked from jwasham/practice-c
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |