Skip to content

Commit

Permalink
Add cpp codes cmake build method (krahets#419)
Browse files Browse the repository at this point in the history
* feat(codes/cpp): Add cmake build method

* feat(codes/cpp): Modify the cpp support version to c++17

* feat(codes/cpp): fix graph_adjacency_list.cpp cannot be compiled into an executable

* style(codes/cpp): Adjust the code to enhance compatibility.

* feat(codes/cpp): Change cpp version from 17 to 11.
  • Loading branch information
Gonglja authored Mar 14, 2023
1 parent d09b1e4 commit 567497a
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 1 deletion.
16 changes: 16 additions & 0 deletions codes/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.10)
project(hello_algo CXX)

set(CMAKE_CXX_STANDARD 11)

include_directories(./include)

add_subdirectory(chapter_tree)
add_subdirectory(chapter_stack_and_queue)
add_subdirectory(chapter_sorting)
add_subdirectory(chapter_searching)
add_subdirectory(chapter_heap)
add_subdirectory(chapter_graph)
add_subdirectory(chapter_hashing)
add_subdirectory(chapter_computational_complexity)
add_subdirectory(chapter_array_and_linkedlist)
4 changes: 4 additions & 0 deletions codes/cpp/chapter_array_and_linkedlist/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(array array.cpp)
add_executable(linked_list linked_list.cpp)
add_executable(list my_list.cpp)
add_executable(my_list my_list.cpp)
4 changes: 4 additions & 0 deletions codes/cpp/chapter_computational_complexity/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(leetcode_two_sum leetcode_two_sum.cpp)
add_executable(space_complexity space_complexity.cpp )
add_executable(time_complexity time_complexity.cpp)
add_executable(worst_best_time_complexity worst_best_time_complexity.cpp)
5 changes: 5 additions & 0 deletions codes/cpp/chapter_graph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(graph_bfs graph_bfs.cpp)
add_executable(graph_dfs graph_dfs.cpp)
# add_executable(graph_adjacency_list graph_adjacency_list.cpp)
add_executable(graph_adjacency_list_test graph_adjacency_list_test.cpp)
add_executable(graph_adjacency_matrix graph_adjacency_matrix.cpp)
4 changes: 3 additions & 1 deletion codes/cpp/chapter_graph/graph_adjacency_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ class GraphAdjList {
/* 打印邻接表 */
void print() {
cout << "邻接表 =" << endl;
for (auto& [key, vec] : adjList) {
for (auto& adj : adjList) {
const auto& key= adj.first;
const auto& vec = adj.second;
cout << key->val << ": ";
PrintUtil::printVector(vetsToVals(vec));
}
Expand Down
2 changes: 2 additions & 0 deletions codes/cpp/chapter_hashing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_executable(array_hash_map array_hash_map.cpp)
add_executable(hash_map hash_map.cpp)
2 changes: 2 additions & 0 deletions codes/cpp/chapter_heap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_executable(heap heap.cpp)
add_executable(my_heap my_heap.cpp)
3 changes: 3 additions & 0 deletions codes/cpp/chapter_searching/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(binary_search binary_search.cpp)
add_executable(hashing_search hashing_search.cpp)
add_executable(linear_search linear_search.cpp)
4 changes: 4 additions & 0 deletions codes/cpp/chapter_sorting/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(bubble_sort bubble_sort.cpp)
add_executable(insertion_sort insertion_sort.cpp)
add_executable(merge_sort merge_sort.cpp)
add_executable(quick_sort quick_sort.cpp)
9 changes: 9 additions & 0 deletions codes/cpp/chapter_stack_and_queue/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_executable(array_deque array_deque.cpp)
add_executable(array_queue array_queue.cpp)
add_executable(array_stack array_stack.cpp)
add_executable(deque deque.cpp)
add_executable(linkedlist_deque linkedlist_deque.cpp)
add_executable(linkedlist_queue linkedlist_queue.cpp)
add_executable(linkedlist_stack linkedlist_stack.cpp)
add_executable(queue queue.cpp)
add_executable(stack stack.cpp)
5 changes: 5 additions & 0 deletions codes/cpp/chapter_tree/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(avl_tree avl_tree.cpp)
add_executable(binary_search_tree binary_search_tree.cpp)
add_executable(binary_tree binary_tree.cpp)
add_executable(binary_tree_bfs binary_tree_bfs.cpp)
add_executable(binary_tree_dfs binary_tree_dfs.cpp)
4 changes: 4 additions & 0 deletions codes/cpp/include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(include
include.hpp PrintUtil.hpp
ListNode.hpp TreeNode.hpp
Vertex.hpp)

0 comments on commit 567497a

Please sign in to comment.