-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
fhlasek/fixgraph: refactor of graph/ to follow the linter style #986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
7adb0d8
improved connected components
ayaankhan98 117c836
formatting source-code for 7adb0d8d5e534324f9f713b3f0dd19823b6ed768
f5a35eb
fix: dijkstra.cpp
ayaankhan98 56556a8
resolved merge conflict
ayaankhan98 541d3bf
formatting source-code for 56556a81fbb1ff545f80cdf204e4bdfc3223d55c
54fd715
Added CMakeLists.txt
ayaankhan98 530da97
fix: infinity
ayaankhan98 eb10e84
formatting source-code for 530da97aec01cfc1a1a0132a4875ea62a746858e
257d0b1
Merge branch 'master' into fixgraph
ayaankhan98 d141aba
Update graph/CMakeLists.txt
ayaankhan98 483e00c
Update CMakeLists.txt
ayaankhan98 0023339
fix: clang-tidy errors
ayaankhan98 cbb43c9
fix: build
ayaankhan98 c107f99
Merge branch 'master' into fixgraph
ayaankhan98 e2f344c
Fix linter warnings in fixgraph branch.
fhlasek f1b909c
Merge remote-tracking branch 'upstream/fixgraph' into fixgraph
fhlasek edf7b4d
Merge branch 'fixgraph_fixlint' into fixgraph
fhlasek 1c5f229
Refactor lowest common ancestor
fhlasek 0c10e6f
Fix linter for topological_sort_by_kahns_algo
fhlasek 6be3336
Remove unused global variable from dfs_with_stack
fhlasek 891e0dd
Fix linter for dfs_with_stack.
fhlasek d2b7015
Remove unused global variable from graph/kruskal.
fhlasek ef031dc
Rename global variable from v to edges in kruskal.
fhlasek ac26555
Refactor prim
fhlasek 95227af
Fix linter for connected_components_with_dsu
fhlasek 146f1c0
Fix linter warnings in ford_fulkerson
fhlasek 1f9da87
Fix global variable name for connected_component_with_dsu.
fhlasek 5dbf857
Fix global variable name in topological_sort.
fhlasek e0b5833
Merge branch 'master' into fixgraph
fhlasek a2178f3
updating DIRECTORY.md
ce0896f
Merge remote-tracking branch 'upstream/master' into fixgraph
fhlasek b7383ed
Undo changs in cycle check.
fhlasek 2e43bbd
Rename dfs to depth_first_search.:
fhlasek f7ff88e
updating DIRECTORY.md
95f6c6e
Merge branch 'master' into fixgraph
fhlasek ed5213e
Merge remote-tracking branch 'upstream/master' into fixgraph
fhlasek efbcaf2
Merge branch 'master' into fixgraph
fhlasek 604945b
Merge branch 'master' into fixgraph
fhlasek 78ecea3
updating DIRECTORY.md
d50f1c6
updating DIRECTORY.md
990e578
Merge remote-tracking branch 'upstream/master'
fhlasek befec35
Merge branch 'master' into fixgraph
fhlasek 9927b46
updating DIRECTORY.md
c1a2e33
Adjust comment.
fhlasek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,20 @@ | ||
| # If necessary, use the RELATIVE flag, otherwise each source file may be listed | ||
| # with full pathname. RELATIVE may makes it easier to extract an executable name | ||
| # automatically. | ||
| file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) | ||
| # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) | ||
| # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) | ||
| foreach( testsourcefile ${APP_SOURCES} ) | ||
| # I used a simple string replace, to cut off .cpp. | ||
| string( REPLACE ".cpp" "" testname ${testsourcefile} ) | ||
| add_executable( ${testname} ${testsourcefile} ) | ||
|
|
||
| set_target_properties(${testname} PROPERTIES | ||
| LINKER_LANGUAGE CXX | ||
| ) | ||
| if(OpenMP_CXX_FOUND) | ||
| target_link_libraries(${testname} OpenMP::OpenMP_CXX) | ||
| endif() | ||
| install(TARGETS ${testname} DESTINATION "bin/graph") | ||
|
|
||
| endforeach( testsourcefile ${APP_SOURCES} ) |
This file contains hidden or 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 hidden or 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,133 @@ | ||
| /** | ||
| * | ||
| * \file | ||
| * \brief [Depth First Search Algorithm | ||
| * (Depth First Search)](https://en.wikipedia.org/wiki/Depth-first_search) | ||
| * | ||
| * \author [Ayaan Khan](http://github.com/ayaankhan98) | ||
| * | ||
| * \details | ||
| * Depth First Search also quoted as DFS is a Graph Traversal Algorithm. | ||
| * Time Complexity O(|V| + |E|) where V is number of vertices and E | ||
| * is number of edges in graph. | ||
| * | ||
| * Application of Depth First Search are | ||
| * | ||
| * 1. Finding connected components | ||
| * 2. Finding 2-(edge or vertex)-connected components. | ||
| * 3. Finding 3-(edge or vertex)-connected components. | ||
| * 4. Finding the bridges of a graph. | ||
| * 5. Generating words in order to plot the limit set of a group. | ||
| * 6. Finding strongly connected components. | ||
| * | ||
| * And there are many more... | ||
| * | ||
| * <h4>Working</h4> | ||
| * 1. Mark all vertices as unvisited first | ||
| * 2. start exploring from some starting vertex. | ||
| * | ||
| * While exploring vertex we mark the vertex as visited | ||
| * and start exploring the vertices connected to this | ||
| * vertex in recursive way. | ||
| * | ||
| */ | ||
|
|
||
| #include <algorithm> | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| /** | ||
| * | ||
| * \namespace graph | ||
| * \brief Graph Algorithms | ||
| * | ||
| */ | ||
| namespace graph { | ||
| /** | ||
| * \brief | ||
| * Adds and edge between two vertices of graph say u and v in this | ||
| * case. | ||
| * | ||
| * @param adj Adjacency list representation of graph | ||
| * @param u first vertex | ||
| * @param v second vertex | ||
| * | ||
| */ | ||
| void addEdge(std::vector<std::vector<size_t>> *adj, size_t u, size_t v) { | ||
| /* | ||
| * | ||
| * Here we are considering undirected graph that's the | ||
| * reason we are adding v to the adjacency list representation of u | ||
| * and also adding u to the adjacency list representation of v | ||
| * | ||
| */ | ||
| (*adj)[u - 1].push_back(v - 1); | ||
| (*adj)[v - 1].push_back(u - 1); | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * \brief | ||
| * Explores the given vertex, exploring a vertex means traversing | ||
| * over all the vertices which are connected to the vertex that is | ||
| * currently being explored. | ||
| * | ||
| * @param adj garph | ||
| * @param v vertex to be explored | ||
| * @param visited already visited vertices | ||
| * | ||
| */ | ||
| void explore(const std::vector<std::vector<size_t>> &adj, size_t v, | ||
| std::vector<bool> *visited) { | ||
| std::cout << v + 1 << " "; | ||
| (*visited)[v] = true; | ||
| for (auto x : adj[v]) { | ||
| if (!(*visited)[x]) { | ||
| explore(adj, x, visited); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * \brief | ||
| * initiates depth first search algorithm. | ||
| * | ||
| * @param adj adjacency list of graph | ||
| * @param start vertex from where DFS starts traversing. | ||
| * | ||
| */ | ||
| void depth_first_search(const std::vector<std::vector<size_t>> &adj, | ||
| size_t start) { | ||
| size_t vertices = adj.size(); | ||
|
|
||
| std::vector<bool> visited(vertices, false); | ||
| explore(adj, start, &visited); | ||
| } | ||
| } // namespace graph | ||
|
|
||
| /** Main function */ | ||
| int main() { | ||
| size_t vertices = 0, edges = 0; | ||
| std::cout << "Enter the Vertices : "; | ||
| std::cin >> vertices; | ||
| std::cout << "Enter the Edges : "; | ||
| std::cin >> edges; | ||
|
|
||
| /// creating graph | ||
| std::vector<std::vector<size_t>> adj(vertices, std::vector<size_t>()); | ||
|
|
||
| /// taking input for edges | ||
| std::cout << "Enter the vertices which have edges between them : " | ||
| << std::endl; | ||
| while (edges--) { | ||
| size_t u = 0, v = 0; | ||
| std::cin >> u >> v; | ||
| graph::addEdge(&adj, u, v); | ||
| } | ||
|
|
||
| /// running depth first search over graph | ||
| graph::depth_first_search(adj, 2); | ||
|
|
||
| std::cout << std::endl; | ||
| return 0; | ||
| } |
This file contains hidden or 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,46 @@ | ||
| #include <iostream> | ||
| #include <list> | ||
| #include <vector> | ||
| #include <stack> | ||
|
|
||
| constexpr int WHITE = 0; | ||
| constexpr int GREY = 1; | ||
| constexpr int BLACK = 2; | ||
| constexpr int INF = 99999; | ||
|
|
||
| void dfs(const std::vector< std::list<int> > &graph, int start) { | ||
| std::vector<int> checked(graph.size(), WHITE); | ||
| checked[start] = GREY; | ||
| std::stack<int> stack; | ||
| stack.push(start); | ||
| while (!stack.empty()) { | ||
| int act = stack.top(); | ||
| stack.pop(); | ||
|
|
||
| if (checked[act] == GREY) { | ||
| std::cout << act << ' '; | ||
| for (auto it : graph[act]) { | ||
| stack.push(it); | ||
| if (checked[it] != BLACK) { | ||
| checked[it] = GREY; | ||
| } | ||
| } | ||
| checked[act] = BLACK; // nodo controllato | ||
| } | ||
| } | ||
| } | ||
|
|
||
| int main() { | ||
| int n = 0; | ||
| std::cin >> n; | ||
| std::vector< std::list<int> > graph(INF); | ||
| for (int i = 0; i < n; ++i) { | ||
| int u = 0, w = 0; | ||
| std::cin >> u >> w; | ||
| graph[u].push_back(w); | ||
| } | ||
|
|
||
| dfs(graph, 0); | ||
|
|
||
| return 0; | ||
| } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.