Compare commits

..

No commits in common. "master" and "2845b020aee7ab4349a0f696d3ede2377b2d3884" have entirely different histories.

227 changed files with 893 additions and 9067 deletions

2
.gitignore vendored
View File

@ -10,5 +10,3 @@
**/Makefile **/Makefile
**/*.cbp **/*.cbp
**/node-modules/ **/node-modules/
**/CMakeLists.txt.user
**/catch2/bin/

View File

@ -7,10 +7,7 @@ github.com/shaunrd0/klips/
├── ansible # Ansible roles, playbooks, and examples ├── ansible # Ansible roles, playbooks, and examples
├── blockchain # Blockchain related project templates and examples ├── blockchain # Blockchain related project templates and examples
├── cpp # C++ programs, datastructures, and other examples ├── cpp # C++ programs, datastructures, and other examples
├── dotnet # .NET projects and examples
├── figlet # Figlet fonts I like :) ├── figlet # Figlet fonts I like :)
├── javascript # Javascript projects and examples
├── python # Python scripts or tools I've made
├── README.md ├── README.md
└── scripts # Bash scripts └── scripts # Bash scripts
``` ```

View File

@ -1,13 +1,13 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A root project for practicing C++ ## ## About: A root project for practicing C++ ##
## This project can be built to debug and run all nested projects ## ## This project can be built to debug and run all nested projects ##
## Or, any subdirectory with a project() statement can be selected ## ## Or, any subdirectory with a project() statement can be selected ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project( project(
@ -18,14 +18,10 @@ project(
) )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_compile_options("-Wall")
add_subdirectory(algorithms) add_subdirectory(algorithms)
add_subdirectory(catch2) add_subdirectory(cmake)
add_subdirectory(cmake-example)
add_subdirectory(cryptography) add_subdirectory(cryptography)
add_subdirectory(datastructs) add_subdirectory(datastructs)
add_subdirectory(graphics) add_subdirectory(graphics)
add_subdirectory(multithreading)
add_subdirectory(patterns) add_subdirectory(patterns)
add_subdirectory(qt)

View File

@ -2,14 +2,12 @@
```bash ```bash
shaunrd0/klips/cpp/ shaunrd0/klips/cpp/
├── algorithms # Examples of various algorithms written in C++ ├── algorithms # Examples of various algorithms written in C++
├── cmake # Example of using cmake to build and organize larger projects ├── cmake # Example of using cmake to build and organize larger projects
├── cryptography # Examples of encrypting / decrypting using ciphers in C++ ├── cryptography # Examples of encrypting / decrypting using ciphers in C++
├── datastructs # Collection of useful datastructures written in C++ ├── datastructs # Collection of useful datastructures written in C++
├── graphics # Examples of graphics projects written in C++ ├── graphics # Examples of graphics projects written in C++
├── multithreading # Basic multithreading examples in C++ ├── patterns # Examples of various design patterns written in C++
├── patterns # Examples of various design patterns written in C++
├── qt # Qt project examples using C++
└── README.md └── README.md
``` ```

View File

@ -1,11 +1,11 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A root project for practicing algorithms in C++ ## ## About: A root project for practicing algorithms in C++ ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( project (

View File

@ -1,11 +1,11 @@
############################################################################### ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A root project for practicing graph algorithms in C++ ## ## About: A root project for practicing graph algorithms in C++ ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
############################################################################## ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( project (

View File

@ -1,10 +1,11 @@
################################################################################ ################################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A root project for practicing graph algorithms in C++ ## ## About: A root project for practicing graph algorithms in C++ ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ################################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
@ -15,7 +16,7 @@ project(
LANGUAGES CXX LANGUAGES CXX
) )
add_executable( add_library(lib-graph-object "lib-graph.cpp")
algo-graphs-object graph.cpp
lib-graph.cpp lib-graph.hpp add_executable(graph-test-object "graph.cpp")
) target_link_libraries(graph-test-object lib-graph-object)

View File

@ -1,7 +1,8 @@
/*############################################################################## /*##############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: Driver program to test object graph implementation ## ## About: An example of an object graph implementation ##
## Algorithms in this example are found in MIT Intro to Algorithms ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ################################################################################

View File

@ -1,8 +1,7 @@
/*############################################################################## /*##############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of an object graph implementation ## ## About: Driver program to test object graph implementation ##
## Algorithms in this example are found in MIT Intro to Algorithms ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ################################################################################
@ -184,3 +183,4 @@ std::vector<Node> Graph::TopologicalSort(const Node &startNode) const
// + Output is handled in main as FILO, similar to a stack // + Output is handled in main as FILO, similar to a stack
return order; return order;
} }

View File

@ -1,6 +1,6 @@
/*############################################################################## /*##############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of an object graph implementation ## ## About: An example of an object graph implementation ##
## Algorithms in this example are found in MIT Intro to Algorithms ## ## Algorithms in this example are found in MIT Intro to Algorithms ##
## ## ## ##
@ -10,14 +10,51 @@
#ifndef LIB_GRAPH_HPP #ifndef LIB_GRAPH_HPP
#define LIB_GRAPH_HPP #define LIB_GRAPH_HPP
#include <algorithm>
#include <iostream> #include <iostream>
#include <algorithm>
#include <map> #include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
/******************************************************************************/
// Structures for tracking information gathered from various traversals
struct Node;
// Color represents the discovery status of any given node
// + White is undiscovered, Gray is in progress, Black is fully discovered
enum Color {White, Gray, Black};
// Information used in all searches
struct SearchInfo {
// Coloring of the nodes is used in both DFS and BFS
Color discovered = White;
};
// Information that is only used in BFS
struct BFS : SearchInfo {
// Used to represent distance from start node
int distance = 0;
// Used to represent the parent node that discovered this node
// + If we use this node as the starting point, this will remain a nullptr
const Node *predecessor = nullptr;
};
// Information that is only used in DFS
struct DFS : SearchInfo {
// Create a pair to track discovery / finish time
// + Discovery time is the iteration the node is first discovered
// + Finish time is the iteration the node has been checked completely
// ++ A finished node has considered all adjacent nodes
std::pair<int, int> discoveryFinish;
};
// Store search information in unordered_maps so we can pass it around easily
// + Allows each node to store relative information on the traversal
using InfoBFS = std::unordered_map<int, struct BFS>;
using InfoDFS = std::unordered_map<int, struct DFS>;
/******************************************************************************/ /******************************************************************************/
@ -26,16 +63,14 @@ struct Node {
public: public:
// Constructors // Constructors
Node(const Node &rhs) = default; Node(const Node &rhs) = default;
Node & operator=(Node rhs) Node & operator=(Node rhs) {
{
if (this == &rhs) return *this; if (this == &rhs) return *this;
swap(*this, rhs); swap(*this, rhs);
return *this; return *this;
} }
Node(int num, std::vector<int> adj) : number(num), adjacent(std::move(adj)) {} Node(int num, std::vector<int> adj) : number(num), adjacent(std::move(adj)) {}
friend void swap(Node &a, Node &b) friend void swap(Node &a, Node &b) {
{
std::swap(a.number, b.number); std::swap(a.number, b.number);
std::swap(a.adjacent, b.adjacent); std::swap(a.adjacent, b.adjacent);
} }
@ -50,61 +85,8 @@ public:
}; };
/******************************************************************************/
// Base struct for storing traversal information on all nodes
// Color represents the discovery status of any given node
enum Color {
// Node is marked as undiscovered
White,
// Node discovery is in progress; Some adjacent nodes have not been checked
Gray,
// Node has been discovered; All adjacent nodes have been checked
Black
};
// Information used in all searches tracked for each node
struct NodeInfo {
// Coloring of the nodes is used in both DFS and BFS
Color discovered = White;
};
/******************************************************************************/
// BFS search information struct
// Node information that is only used in BFS
struct BFS : NodeInfo {
// Used to represent distance from start node
int distance = 0;
// Used to represent the parent node that discovered this node
// + If we use this node as the starting point, this will remain a nullptr
const Node *predecessor = nullptr;
};
// Store search information in unordered_maps so we can pass it around easily
// + Allows each node to store relative information on the traversal
using InfoBFS = std::unordered_map<int, struct BFS>;
/******************************************************************************/
// DFS search information struct
// Node information that is only used in DFS
struct DFS : NodeInfo {
// Create a pair to track discovery / finish time
// + Discovery time is the iteration the node is first discovered
// + Finish time is the iteration the node has been checked completely
// ++ A finished node has considered all adjacent nodes
std::pair<int, int> discoveryFinish;
};
using InfoDFS = std::unordered_map<int, struct DFS>;
/******************************************************************************/ /******************************************************************************/
// Graph class declaration // Graph class declaration
class Graph { class Graph {
public: public:
// Constructor // Constructor
@ -119,7 +101,7 @@ public:
// An alternate DFS that checks each node of the graph beginning at startNode // An alternate DFS that checks each node of the graph beginning at startNode
InfoDFS DFS(const Node &startNode) const; InfoDFS DFS(const Node &startNode) const;
// Visit function is used in both versions of DFS // Visit function is used in both versions of DFS
void DFSVisit(int &time, const Node& startNode, InfoDFS &dfs) const; void DFSVisit(int &time, const Node& startNode, InfoDFS &searchInfo) const;
// Topological sort, using DFS // Topological sort, using DFS
std::vector<Node> TopologicalSort(const Node &startNode) const; std::vector<Node> TopologicalSort(const Node &startNode) const;

View File

@ -1,10 +1,11 @@
############################################################################### ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A CMakeLists configuration to test a simple graph implementation ## ## About: A CMakeLists configuration to test a simple graph implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
############################################################################## ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
@ -15,7 +16,7 @@ project(
LANGUAGES CXX LANGUAGES CXX
) )
add_executable( add_library(lib-graph-simple "lib-graph.cpp")
algo-graphs-simple graph.cpp
lib-graph.cpp lib-graph.hpp add_executable(graph-test-simple "graph.cpp")
) target_link_libraries(graph-test-simple lib-graph-simple)

View File

@ -1,6 +1,6 @@
/*############################################################################## /*##############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: Driver program to test a simple graph implementation ## ## About: Driver program to test a simple graph implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################## /*##############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a simple graph implementation ## ## About: An example of a simple graph implementation ##
## Algorithms in this example are found in MIT Intro to Algorithms ## ## Algorithms in this example are found in MIT Intro to Algorithms ##
## ## ## ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a simple graph implementation ## ## About: An example of a simple graph implementation ##
## Algorithms in this example are found in MIT Intro to Algorithms ## ## Algorithms in this example are found in MIT Intro to Algorithms ##
## ## ## ##
@ -12,9 +12,9 @@
#include <iostream> #include <iostream>
#include <queue> #include <queue>
#include <vector>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <vector>
class Graph { class Graph {

View File

@ -1,10 +1,11 @@
################################################################################ ################################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists to test templated graph implementation ## ## About: A basic CMakeLists to test templated graph implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ################################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
@ -15,4 +16,7 @@ project(
LANGUAGES CXX LANGUAGES CXX
) )
add_executable(algo-graphs-templated graph.cpp) #add_library(lib-graph-templated "lib-graph.cpp")
add_executable(graph-test-templated "graph.cpp")
#target_link_libraries(graph-test-templated lib-graph-templated)

View File

@ -1,7 +1,7 @@
/*############################################################################## /*##############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: Driver program to test templated object graph implementation ## ## About: An example of a weighted graph implementation ##
## Algorithms in this example are found in MIT Intro to Algorithms ## ## Algorithms in this example are found in MIT Intro to Algorithms ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,10 +1,12 @@
/*############################################################################## /*##############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: Text viewer for signals and slots examples ## ## About: Driver program to test object graph implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ################################################################################
*/ */
#include "text-view.h" #include "lib-graph.hpp"

View File

@ -1,7 +1,7 @@
/*############################################################################## /*##############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a templated object graph implementation ## ## About: An example of an object graph implementation ##
## Algorithms in this example are found in MIT Intro to Algorithms ## ## Algorithms in this example are found in MIT Intro to Algorithms ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
@ -10,88 +10,38 @@
#ifndef LIB_GRAPH_HPP #ifndef LIB_GRAPH_HPP
#define LIB_GRAPH_HPP #define LIB_GRAPH_HPP
#include <algorithm>
#include <iostream> #include <iostream>
#include <algorithm>
#include <map> #include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <queue>
#include <unordered_set>
/******************************************************************************/ #include <unordered_map>
// Node structure for representing a graph
template <typename T>
struct Node {
public:
template <typename> friend class Graph;
template <typename> friend class InfoMST;
// Constructors
Node(const Node &rhs) = default;
Node & operator=(Node rhs)
{
if (this == &rhs) return *this;
swap(*this, rhs);
return *this;
}
Node(T data, const std::vector<std::pair<T, int>> &adj) : data_(data)
{
// Place each adjacent node in vector into our unordered_map of edges
for (const auto &i : adj) adjacent_.emplace(i.first, i.second);
}
friend void swap(Node &a, Node &b)
{
std::swap(a.data_, b.data_);
std::swap(a.adjacent_, b.adjacent_);
}
// Operators
// Define operator== for std::find; And comparisons between nodes
bool operator==(const Node<T> &b) const { return this->data_ == b.data_;}
// Define an operator!= for comparing nodes for inequality
bool operator!=(const Node<T> &b) const { return this->data_ != b.data_;}
// Accessors
inline T GetData() const { return data_;}
inline std::unordered_map<int, int> GetAdjacent() const { return adjacent_;}
private:
T data_;
// Adjacent stored in an unordered_map<adj.number, edgeWeight>
std::unordered_map<T, int> adjacent_;
};
/******************************************************************************/ /******************************************************************************/
// Base struct for storing traversal information on all nodes // Base struct for storing traversal information on all nodes
// Color represents the discovery status of any given node template <typename T> struct Node;
enum Color {
// Node is marked as undiscovered
White,
// Node discovery is in progress; Some adjacent nodes have not been checked
Gray,
// Node has been discovered; All adjacent nodes have been checked
Black
};
// Information used in all searches tracked for each node // Color represents the discovery status of any given node
struct NodeInfo { // + White is undiscovered, Gray is in progress, Black is fully discovered
enum Color {White, Gray, Black};
// Information used in all searches
struct SearchInfo {
// Coloring of the nodes is used in both DFS and BFS // Coloring of the nodes is used in both DFS and BFS
Color discovered = White; Color discovered = White;
}; };
/******************************************************************************/ /******************************************************************************/
// BFS search information struct // BFS search information structs
// Node information that is only used in BFS // Information that is only used in BFS
template <typename T> template <typename T>
struct BFS : NodeInfo { struct BFS : SearchInfo {
// Used to represent distance from start node // Used to represent distance from start node
int distance = 0; int distance = 0;
// Used to represent the parent node that discovered this node // Used to represent the parent node that discovered this node
@ -99,16 +49,12 @@ struct BFS : NodeInfo {
const Node<T> *predecessor = nullptr; const Node<T> *predecessor = nullptr;
}; };
// Store search information in unordered_maps so we can pass it around easily
// + Allows each node to store relative information on the traversal
template <typename T> using InfoBFS = std::unordered_map<T, struct BFS<T>>;
/******************************************************************************/ /******************************************************************************/
// DFS search information struct // DFS search information structs
// Node information that is only used in DFS // Information that is only used in DFS
struct DFS : NodeInfo { struct DFS : SearchInfo {
// Create a pair to track discovery / finish time // Create a pair to track discovery / finish time
// + Discovery time is the iteration the node is first discovered // + Discovery time is the iteration the node is first discovered
// + Finish time is the iteration the node has been checked completely // + Finish time is the iteration the node has been checked completely
@ -116,16 +62,22 @@ struct DFS : NodeInfo {
std::pair<int, int> discoveryFinish; std::pair<int, int> discoveryFinish;
}; };
template <typename T> using InfoDFS = std::unordered_map<T, struct DFS>;
/******************************************************************************/ /******************************************************************************/
// MST search information struct // Alias types for storing search information structures
// Store search information in unordered_maps so we can pass it around easily
// + Allows each node to store relative information on the traversal
template <typename T> using InfoBFS = std::unordered_map<T, struct BFS<T>>;
template <typename T> using InfoDFS = std::unordered_map<T, struct DFS>;
// Edges stored as multimap<weight, pair<nodeA.data_, nodeB.data_>> // Edges stored as multimap<weight, pair<nodeA.data_, nodeB.data_>>
template <typename T> using Edges = std::multimap<int, std::pair<T, T>>; template <typename T> using Edges = std::multimap<int, std::pair<T, T>>;
struct MST : NodeInfo {
/******************************************************************************/
// MST search information structs
struct MST : SearchInfo {
int32_t parent = INT32_MIN; int32_t parent = INT32_MIN;
int rank = 0; int rank = 0;
}; };
@ -134,9 +86,8 @@ template <typename T>
struct InfoMST { struct InfoMST {
template <typename> friend class Graph; template <typename> friend class Graph;
explicit InfoMST(const std::vector<Node<T>> &nodes) explicit InfoMST(const std::vector<Node<T>> &nodes) {
{ for (const auto &node : nodes){
for (const auto &node : nodes) {
// Initialize the default values for forest tracked by this struct // Initialize the default values for forest tracked by this struct
// + This data is used in KruskalMST() to find the MST // + This data is used in KruskalMST() to find the MST
MakeSet(node.data_); MakeSet(node.data_);
@ -206,6 +157,51 @@ private:
}; };
/******************************************************************************/
// Node structure for representing a graph
template <typename T>
struct Node {
public:
template <typename> friend class Graph;
template <typename> friend class InfoMST;
// Constructors
Node(const Node &rhs) = default;
Node & operator=(Node rhs) {
if (this == &rhs) return *this;
swap(*this, rhs);
return *this;
}
Node(T data, const std::vector<std::pair<T, int>> &adj)
: data_(data)
{
// Place each adjacent node in vector into our unordered_map of edges
for (const auto &i : adj) adjacent_.emplace(i.first, i.second);
}
friend void swap(Node &a, Node &b) {
std::swap(a.data_, b.data_);
std::swap(a.adjacent_, b.adjacent_);
}
// Operators
// Define operator== for std::find; And comparisons between nodes
bool operator==(const Node<T> &b) const { return this->data_ == b.data_;}
// Define an operator!= for comparing nodes for inequality
bool operator!=(const Node<T> &b) const { return this->data_ != b.data_;}
// Accessors
inline T GetData() const { return data_;}
inline std::unordered_map<int, int> GetAdjacent() const { return adjacent_;}
private:
T data_;
// Adjacent stored in an unordered_map<adj.number, edgeWeight>
std::unordered_map<T, int> adjacent_;
};
/******************************************************************************/ /******************************************************************************/
// Templated graph class // Templated graph class
@ -213,7 +209,7 @@ template <class T>
class Graph { class Graph {
public: public:
// Constructor // Constructor
explicit Graph(std::vector<Node<T>> nodes) : nodes_(std::move(nodes)) {} Graph(std::vector<Node<T>> nodes) : nodes_(std::move(nodes)) {}
// Breadth First Search // Breadth First Search
InfoBFS<T> BFS(const Node<T>& startNode) const; InfoBFS<T> BFS(const Node<T>& startNode) const;

View File

@ -1,10 +1,11 @@
################################################################################ ################################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists configuration to test RBT implementation ## ## About: A basic CMakeLists configuration to test RBT implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ################################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
@ -15,7 +16,7 @@ project(
LANGUAGES CXX LANGUAGES CXX
) )
add_executable( add_library(lib-graph-weighted "lib-graph.cpp")
algo-graphs-weighted graph.cpp
lib-graph.cpp lib-graph.hpp add_executable(graph-test-weighted "graph.cpp")
) target_link_libraries(graph-test-weighted lib-graph-weighted)

View File

@ -1,7 +1,8 @@
/*############################################################################## /*##############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: Driver program to test weighted graph implementation ## ## About: An example of a weighted graph implementation ##
## Algorithms in this example are found in MIT Intro to Algorithms ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ################################################################################
@ -104,7 +105,7 @@ int main (const int argc, const char * argv[])
// + Chapter 22, Figure 22.4 on DFS // + Chapter 22, Figure 22.4 on DFS
// Unlike the simple-graph example, this final result matches MIT Algorithms // Unlike the simple-graph example, this final result matches MIT Algorithms
// + Aside from the placement of the watch node, which is not connected // + Aside from the placement of the watch node, which is not connected
// + This is because the node is visited after all other nodes are finished // + This is because the node is visited after all other nodes are finished
std::vector<Node> order = std::vector<Node> order =
topologicalGraph.TopologicalSort(topologicalGraph.GetNodeCopy(6)); topologicalGraph.TopologicalSort(topologicalGraph.GetNodeCopy(6));
std::cout << "\nTopological order: "; std::cout << "\nTopological order: ";
@ -156,19 +157,11 @@ int main (const int argc, const char * argv[])
{9, {{3, 2}, {7, 6}}} {9, {{3, 2}, {7, 6}}}
} }
); );
std::cout << "\nChecking weight traversing graph from node 1 using DFS...\n";
InfoDFS resultDFS = graphMST.DFS(graphMST.GetNodeCopy(1));
std::cout << "DFS total weight traversed: " << resultDFS.totalWeight << std::endl;
std::cout << "\nChecking weight traversing graph from node 1 using BFS...\n";
InfoBFS resultBFS = graphMST.BFS(graphMST.GetNodeCopy(1));
std::cout << "BFS total weight traversed: " << resultBFS.totalWeight << std::endl;
InfoMST resultMST = graphMST.KruskalMST(); InfoMST resultMST = graphMST.KruskalMST();
std::cout << "\n\nFinding MST using Kruskal's...\n\nMST result: \n"; std::cout << "Finding MST using Kruskal's...\n\nMST result: \n";
for (const auto &edge : resultMST.edgesMST) { for (const auto &edge : resultMST.edgesMST) {
std::cout << "Connected nodes: " << edge.second.first << "->" std::cout << "Connected nodes: " << edge.second.first << "->"
<< edge.second.second << " with weight of " << edge.first << "\n"; << edge.second.second << " with weight of " << edge.first << "\n";
} }
std::cout << "Total MST weight: " << resultMST.totalWeight << std::endl; std::cout << "Total MST weight: " << resultMST.weightMST << std::endl;
} }

View File

@ -1,8 +1,7 @@
/*############################################################################## /*##############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a weighted graph implementation ## ## About: Driver program to test object graph implementation ##
## Algorithms in this example are found in MIT Intro to Algorithms ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ################################################################################
@ -14,13 +13,13 @@
InfoBFS Graph::BFS(const Node& startNode) const InfoBFS Graph::BFS(const Node& startNode) const
{ {
// Create local object to track the information gathered during traversal // Create local object to track the information gathered during traversal
InfoBFS bfs; InfoBFS searchInfo;
// Create a queue to visit discovered nodes in FIFO order // Create a queue to visit discovered nodes in FIFO order
std::queue<const Node *> visitQueue; std::queue<const Node *> visitQueue;
// Mark the startNode as in progress until we finish checking adjacent nodes // Mark the startNode as in progress until we finish checking adjacent nodes
bfs.nodeInfo[startNode.number].discovered = Gray; searchInfo[startNode.number].discovered = Gray;
// Visit the startNode // Visit the startNode
visitQueue.push(&startNode); visitQueue.push(&startNode);
@ -31,17 +30,17 @@ InfoBFS Graph::BFS(const Node& startNode) const
const Node * thisNode = visitQueue.front(); const Node * thisNode = visitQueue.front();
visitQueue.pop(); visitQueue.pop();
std::cout << "Visiting node " << thisNode->number << std::endl; std::cout << "Visiting node " << thisNode->number << std::endl;
// Check if we have already discovered all the adjacentNodes to thisNode // Check if we have already discovered all the adjacentNodes to thisNode
for (const auto &adjacent : thisNode->adjacent) { for (const auto &adjacent : thisNode->adjacent) {
if (bfs.nodeInfo[adjacent.first].discovered == White) { if (searchInfo[adjacent.first].discovered == White) {
std::cout << "Found undiscovered adjacentNode: " << adjacent.first std::cout << "Found undiscovered adjacentNode: " << adjacent.first
<< " with weight of " << adjacent.second << std::endl; << "\n";
bfs.totalWeight += adjacent.second;
// Mark the adjacent node as in progress // Mark the adjacent node as in progress
bfs.nodeInfo[adjacent.first].discovered = Gray; searchInfo[adjacent.first].discovered = Gray;
bfs.nodeInfo[adjacent.first].distance = searchInfo[adjacent.first].distance =
bfs.nodeInfo[thisNode->number].distance + 1; searchInfo[thisNode->number].distance + 1;
bfs.nodeInfo[adjacent.first].predecessor = searchInfo[adjacent.first].predecessor =
&GetNode(thisNode->number); &GetNode(thisNode->number);
// Add the discovered node the the visitQueue // Add the discovered node the the visitQueue
@ -49,11 +48,11 @@ InfoBFS Graph::BFS(const Node& startNode) const
} }
} }
// We are finished with this node and the adjacent nodes; Mark it discovered // We are finished with this node and the adjacent nodes; Mark it discovered
bfs.nodeInfo[thisNode->number].discovered = Black; searchInfo[thisNode->number].discovered = Black;
} }
// Return the information gathered from this search, JIC caller needs it // Return the information gathered from this search, JIC caller needs it
return bfs; return searchInfo;
} }
std::deque<Node> Graph::PathBFS(const Node &start, const Node &finish) const std::deque<Node> Graph::PathBFS(const Node &start, const Node &finish) const
@ -62,8 +61,8 @@ std::deque<Node> Graph::PathBFS(const Node &start, const Node &finish) const
// + If the caller modifies these, it will not impact the graph's data // + If the caller modifies these, it will not impact the graph's data
std::deque<Node> path; std::deque<Node> path;
InfoBFS bfs = BFS(start); InfoBFS searchInfo = BFS(start);
const Node * next = bfs.nodeInfo[finish.number].predecessor; const Node * next = searchInfo[finish.number].predecessor;
bool isValid = false; bool isValid = false;
do { do {
// If we have reached the start node, we have found a valid path // If we have reached the start node, we have found a valid path
@ -74,7 +73,7 @@ std::deque<Node> Graph::PathBFS(const Node &start, const Node &finish) const
path.emplace_front(*next); path.emplace_front(*next);
// Move to the next node // Move to the next node
next = bfs.nodeInfo[next->number].predecessor; next = searchInfo[next->number].predecessor;
} while (next != nullptr); } while (next != nullptr);
// Use emplace_back to call Node copy constructor // Use emplace_back to call Node copy constructor
path.emplace_back(finish); path.emplace_back(finish);
@ -89,83 +88,85 @@ std::deque<Node> Graph::PathBFS(const Node &start, const Node &finish) const
InfoDFS Graph::DFS() const InfoDFS Graph::DFS() const
{ {
// Track the nodes we have discovered // Track the nodes we have discovered
InfoDFS dfs; InfoDFS searchInfo;
int time = 0; int time = 0;
// Visit each node in the graph // Visit each node in the graph
for (const auto & node : nodes_) { for (const auto& node : nodes_) {
std::cout << "Visiting node " << node.number << std::endl; std::cout << "Visiting node " << node.number << std::endl;
// If the node is undiscovered, visit it // If the node is undiscovered, visit it
if (dfs.nodeInfo[node.number].discovered == White) { if (searchInfo[node.number].discovered == White) {
std::cout << "Found undiscovered node: " << node.number << std::endl; std::cout << "Found undiscovered node: " << node.number << std::endl;
// Visiting the undiscovered node will check it's adjacent nodes // Visiting the undiscovered node will check it's adjacent nodes
DFSVisit(time, node, dfs); DFSVisit(time, node, searchInfo);
} }
} }
return dfs; return searchInfo;
} }
InfoDFS Graph::DFS(const Node &startNode) const InfoDFS Graph::DFS(const Node &startNode) const
{ {
// Track the nodes we have discovered // Track the nodes we have discovered
InfoDFS dfs; InfoDFS searchInfo;
int time = 0; int time = 0;
auto startIter = auto startIter = std::find(nodes_.begin(), nodes_.end(),
std::find(nodes_.begin(), nodes_.end(), Node(startNode.number, { })); Node(startNode.number, {})
);
// beginning at startNode, visit each node in the graph until we reach the end // beginning at startNode, visit each node in the graph until we reach the end
while (startIter != nodes_.end()) { while (startIter != nodes_.end()) {
std::cout << "Visiting node " << startIter->number << std::endl; std::cout << "Visiting node " << startIter->number << std::endl;
// If the startIter is undiscovered, visit it // If the startIter is undiscovered, visit it
if (dfs.nodeInfo[startIter->number].discovered == White) { if (searchInfo[startIter->number].discovered == White) {
std::cout << "Found undiscovered node: " << startIter->number std::cout << "Found undiscovered node: " << startIter->number << std::endl;
<< std::endl;
// Visiting the undiscovered node will check it's adjacent nodes // Visiting the undiscovered node will check it's adjacent nodes
DFSVisit(time, *startIter, dfs); DFSVisit(time, *startIter, searchInfo);
} }
startIter++; startIter++;
} }
// Once we reach the last node, check the beginning for unchecked nodes // Once we reach the last node, check the beginning for unchecked nodes
startIter = nodes_.begin(); startIter = nodes_.begin();
// Once we reach the initial startNode, we have checked all nodes // Once we reach the initial startNode, we have checked all nodes
while (*startIter != startNode) { while (*startIter != startNode) {
std::cout << "Visiting node " << startIter->number << std::endl; std::cout << "Visiting node " << startIter->number << std::endl;
// If the startIter is undiscovered, visit it // If the startIter is undiscovered, visit it
if (dfs.nodeInfo[startIter->number].discovered == White) { if (searchInfo[startIter->number].discovered == White) {
std::cout << "Found undiscovered node: " << startIter->number << std::endl; std::cout << "Found undiscovered node: " << startIter->number << std::endl;
// Visiting the undiscovered node will check it's adjacent nodes // Visiting the undiscovered node will check it's adjacent nodes
DFSVisit(time, *startIter, dfs); DFSVisit(time, *startIter, searchInfo);
} }
startIter++; startIter++;
} }
return dfs; return searchInfo;
} }
void Graph::DFSVisit(int &time, const Node& startNode, InfoDFS &dfs) const void Graph::DFSVisit(int &time, const Node& startNode, InfoDFS &searchInfo) const
{ {
dfs.nodeInfo[startNode.number].discovered = Gray; searchInfo[startNode.number].discovered = Gray;
time++; time++;
dfs.nodeInfo[startNode.number].discoveryFinish.first = time; searchInfo[startNode.number].discoveryFinish.first = time;
// Check the adjacent nodes of the startNode // Check the adjacent nodes of the startNode
for (const auto & adjacent : startNode.adjacent) { for (const auto &adjacent : startNode.adjacent) {
const auto node = GetNode(adjacent.first); auto iter = std::find(nodes_.begin(), nodes_.end(),
Node(adjacent.first, {}));
// If the adjacentNode is undiscovered, visit it // If the adjacentNode is undiscovered, visit it
// + Offset by 1 to account for 0 index of discovered vector // + Offset by 1 to account for 0 index of discovered vector
if (dfs.nodeInfo[node.number].discovered == White) { if (searchInfo[iter->number].discovered == White) {
std::cout << "Found undiscovered adjacentNode: " << adjacent.first std::cout << "Found undiscovered adjacentNode: "
<< " with weight of " << adjacent.second << std::endl; << GetNode(adjacent.first).number << std::endl;
// Visiting the undiscovered node will check it's adjacent nodes // Visiting the undiscovered node will check it's adjacent nodes
dfs.totalWeight += adjacent.second; DFSVisit(time, *iter, searchInfo);
DFSVisit(time, node, dfs);
} }
} }
dfs.nodeInfo[startNode.number].discovered = Black; searchInfo[startNode.number].discovered = Black;
time++; time++;
dfs.nodeInfo[startNode.number].discoveryFinish.second = time; searchInfo[startNode.number].discoveryFinish.second = time;
} }
std::vector<Node> Graph::TopologicalSort(const Node &startNode) const std::vector<Node> Graph::TopologicalSort(const Node &startNode) const
@ -175,8 +176,8 @@ std::vector<Node> Graph::TopologicalSort(const Node &startNode) const
std::vector<Node> order(nodes_); std::vector<Node> order(nodes_);
auto comp = [&topological](const Node &a, const Node &b) { auto comp = [&topological](const Node &a, const Node &b) {
return (topological.nodeInfo[a.number].discoveryFinish.second < return (topological[a.number].discoveryFinish.second <
topological.nodeInfo[b.number].discoveryFinish.second); topological[b.number].discoveryFinish.second);
}; };
std::sort(order.begin(), order.end(), comp); std::sort(order.begin(), order.end(), comp);
@ -188,26 +189,27 @@ std::vector<Node> Graph::TopologicalSort(const Node &startNode) const
InfoMST Graph::KruskalMST() const InfoMST Graph::KruskalMST() const
{ {
InfoMST mst(nodes_); InfoMST searchInfo(nodes_);
// The ctor for InfoMST initializes all edges within the graph into a multimap // The ctor for InfoMST initializes all edges within the graph into a multimap
// + Key for multimap is edge weight, so they're already sorted in ascending // + Key for multimap is edge weight, so they're already sorted in ascending
// For each edge in the graph, check if they are part of the same tree // For each edge in the graph, check if they are part of the same tree
// + Since we do not want to create a cycle in the MST forest - // + Since we do not want to create a cycle in the MST forest -
// + we don't connect nodes that are part of the same tree // + we don't connect nodes that are part of the same tree
for (const auto &edge : mst.edges) { for (const auto &edge : searchInfo.edges) {
// Two integers representing the node.number for the connected nodes // Two integers representing the node.number for the connected nodes
const int u = edge.second.first; const int u = edge.second.first;
const int v = edge.second.second; const int v = edge.second.second;
// Check if the nodes are of the same tree // Check if the nodes are of the same tree
if (mst.FindSet(u) != mst.FindSet(v)) { if (searchInfo.FindSet(u) != searchInfo.FindSet(v)) {
// If they are not, add the edge to our MST // If they are not, add the edge to our MST
mst.edgesMST.emplace(edge); searchInfo.edgesMST.emplace(edge);
mst.totalWeight += edge.first; searchInfo.weightMST += edge.first;
// Update the forest to reflect this change // Update the forest to reflect this change
mst.Union(u, v); searchInfo.Union(u, v);
} }
} }
return mst; return searchInfo;
} }

View File

@ -1,7 +1,7 @@
/*############################################################################## /*##############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a weighted graph implementation ## ## About: An example of an object graph implementation ##
## Algorithms in this example are found in MIT Intro to Algorithms ## ## Algorithms in this example are found in MIT Intro to Algorithms ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
@ -10,14 +10,56 @@
#ifndef LIB_GRAPH_HPP #ifndef LIB_GRAPH_HPP
#define LIB_GRAPH_HPP #define LIB_GRAPH_HPP
#include <algorithm>
#include <iostream> #include <iostream>
#include <algorithm>
#include <map> #include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
/******************************************************************************/
// Structures for tracking information gathered from various traversals
struct Node;
// Color represents the discovery status of any given node
// + White is undiscovered, Gray is in progress, Black is fully discovered
enum Color {White, Gray, Black};
// Information used in all searches
struct SearchInfo {
// Coloring of the nodes is used in both DFS and BFS
Color discovered = White;
};
// Information that is only used in BFS
struct BFS : SearchInfo {
// Used to represent distance from start node
int distance = 0;
// Used to represent the parent node that discovered this node
// + If we use this node as the starting point, this will remain a nullptr
const Node *predecessor = nullptr;
};
// Information that is only used in DFS
struct DFS : SearchInfo {
// Create a pair to track discovery / finish time
// + Discovery time is the iteration the node is first discovered
// + Finish time is the iteration the node has been checked completely
// ++ A finished node has considered all adjacent nodes
std::pair<int, int> discoveryFinish;
};
struct MST : SearchInfo {
int32_t parent = INT32_MIN;
int rank = 0;
};
// Store search information in unordered_maps so we can pass it around easily
// + Allows each node to store relative information on the traversal
using InfoBFS = std::unordered_map<int, struct BFS>;
using InfoDFS = std::unordered_map<int, struct DFS>;
/******************************************************************************/ /******************************************************************************/
@ -27,8 +69,7 @@ struct Node {
public: public:
// Constructors // Constructors
Node(const Node &rhs) = default; Node(const Node &rhs) = default;
Node & operator=(Node rhs) Node & operator=(Node rhs) {
{
if (this == &rhs) return *this; if (this == &rhs) return *this;
swap(*this, rhs); swap(*this, rhs);
return *this; return *this;
@ -39,8 +80,7 @@ public:
for (const auto &i : adj) adjacent.emplace(i.first, i.second); for (const auto &i : adj) adjacent.emplace(i.first, i.second);
} }
friend void swap(Node &a, Node &b) friend void swap(Node &a, Node &b) {
{
std::swap(a.number, b.number); std::swap(a.number, b.number);
std::swap(a.adjacent, b.adjacent); std::swap(a.adjacent, b.adjacent);
} }
@ -55,81 +95,10 @@ public:
bool operator!=(const Node &b) const { return this->number != b.number;} bool operator!=(const Node &b) const { return this->number != b.number;}
}; };
/******************************************************************************/
// Base struct for storing traversal information on all nodes
// Color represents the discovery status of any given node
enum Color {
// Node is marked as undiscovered
White,
// Node discovery is in progress; Some adjacent nodes have not been checked
Gray,
// Node has been discovered; All adjacent nodes have been checked
Black
};
// Information used in all searches tracked for each node
struct NodeInfo {
// Coloring of the nodes is used in both DFS and BFS
Color discovered = White;
};
// Template for tracking graph information gathered during traversals
// + Used for DFS, BFS, and MST
template <typename T>
struct GraphInfo {
// Store search information in unordered_maps so we can pass it around easily
// + Allows each node to store relative information on the traversal
std::unordered_map<int, T> nodeInfo;
// Track total weight for all traversals
int totalWeight = 0;
};
/******************************************************************************/
// BFS search information struct
// Node search information that is only used in BFS
struct BFS : NodeInfo {
// Used to represent distance from start node
int distance = 0;
// Used to represent the parent node that discovered this node
// + If we use this node as the starting point, this will remain a nullptr
const Node *predecessor = nullptr;
};
struct InfoBFS : GraphInfo<BFS> {/* Members inherited from GraphInfo */};
/******************************************************************************/
// DFS search information struct
// Information that is only used in DFS
struct DFS : NodeInfo {
// Create a pair to track discovery / finish time
// + Discovery time is the iteration the node is first discovered
// + Finish time is the iteration the node has been checked completely
// ++ A finished node has considered all adjacent nodes
std::pair<int, int> discoveryFinish;
};
struct InfoDFS : GraphInfo<DFS> {/* Members inherited from GraphInfo */};
/******************************************************************************/
// MST search information struct
struct MST : NodeInfo {
int32_t parent = INT32_MIN;
int rank = 0;
};
using Edges = std::multimap<int, std::pair<int, int>>; using Edges = std::multimap<int, std::pair<int, int>>;
struct InfoMST : GraphInfo<MST>{ struct InfoMST {
explicit InfoMST(const std::vector<Node> &nodes) explicit InfoMST(const std::vector<Node> &nodes) {
{ for (const auto &node : nodes){
for (const auto &node : nodes) {
// Initialize the default values for forest tracked by this struct // Initialize the default values for forest tracked by this struct
// + This data is used in KruskalMST() to find the MST // + This data is used in KruskalMST() to find the MST
MakeSet(node.number); MakeSet(node.number);
@ -144,17 +113,20 @@ struct InfoMST : GraphInfo<MST>{
} }
} }
std::unordered_map<int, struct MST> searchInfo;
// All of the edges within our graph // All of the edges within our graph
// + Since each node stores its own edges, this is initialized in InfoMST ctor // + Since each node stores its own edges, this is initialized in InfoMST ctor
Edges edges; Edges edges;
// A multimap of the edges found for our MST // A multimap of the edges found for our MST
Edges edgesMST; Edges edgesMST;
// The total weight of our resulting MST
int weightMST = 0;
void MakeSet(int x) void MakeSet(int x)
{ {
nodeInfo[x].parent = x; searchInfo[x].parent = x;
nodeInfo[x].rank = 0; searchInfo[x].rank = 0;
} }
void Union(int x, int y) void Union(int x, int y)
@ -164,30 +136,29 @@ struct InfoMST : GraphInfo<MST>{
void Link(int x, int y) void Link(int x, int y)
{ {
if (nodeInfo[x].rank > nodeInfo[y].rank) { if (searchInfo[x].rank > searchInfo[y].rank) {
nodeInfo[y].parent = x; searchInfo[y].parent = x;
} }
else { else {
nodeInfo[x].parent = y; searchInfo[x].parent = y;
if (nodeInfo[x].rank == nodeInfo[y].rank) { if (searchInfo[x].rank == searchInfo[y].rank) {
nodeInfo[y].rank += 1; searchInfo[y].rank += 1;
} }
} }
} }
int FindSet(int x) int FindSet(int x)
{ {
if (x != nodeInfo[x].parent) { if (x != searchInfo[x].parent) {
nodeInfo[x].parent = FindSet(nodeInfo[x].parent); searchInfo[x].parent = FindSet(searchInfo[x].parent);
} }
return nodeInfo[x].parent; return searchInfo[x].parent;
} }
};
};
/******************************************************************************/ /******************************************************************************/
// Graph class declaration // Graph class declaration
class Graph { class Graph {
public: public:
// Constructor // Constructor
@ -202,7 +173,7 @@ public:
// An alternate DFS that checks each node of the graph beginning at startNode // An alternate DFS that checks each node of the graph beginning at startNode
InfoDFS DFS(const Node &startNode) const; InfoDFS DFS(const Node &startNode) const;
// Visit function is used in both versions of DFS // Visit function is used in both versions of DFS
void DFSVisit(int &time, const Node& startNode, InfoDFS &dfs) const; void DFSVisit(int &time, const Node& startNode, InfoDFS &searchInfo) const;
// Topological sort, using DFS // Topological sort, using DFS
std::vector<Node> TopologicalSort(const Node &startNode) const; std::vector<Node> TopologicalSort(const Node &startNode) const;
// Kruskal's MST // Kruskal's MST

View File

@ -1,11 +1,11 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A root project for practicing sorting algorithms in C++ ## ## About: A root project for practicing sorting algorithms in C++ ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( project (

View File

@ -1,6 +1,6 @@
############################################################################### ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists configuration to practice bubble sort ## ## About: A basic CMakeLists configuration to practice bubble sort ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
@ -9,7 +9,7 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(BubbleSort LANGUAGES CXX) project(BubbleSort LANGUAGES CXX)
add_executable( add_executable(bubble-sort "bubble-sort.cpp")
algo-sort-bubble bubble-sort.cpp
lib-bubble.cpp lib-bubble.hpp add_library(lib-bubble "lib-bubble.cpp")
) target_link_libraries(bubble-sort lib-bubble)

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of bubble sort using a custom library ## ## About: An example implementation of bubble sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of bubble sort using a custom library ## ## About: An example implementation of bubble sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
@ -15,9 +15,9 @@
void BubbleSort(std::vector<int> &array) void BubbleSort(std::vector<int> &array)
{ {
// For each value within the set, starting at 0 // For each value within the set, starting at 0
for (size_t sortedPivot = 0; sortedPivot < array.size(); sortedPivot++) { for (int sortedPivot = 0; sortedPivot < array.size(); sortedPivot++) {
// Check every other remaining value in the set // Check every other remaining value in the set
for (size_t j = array.size() - 1; j > sortedPivot; j--) { for (int j = array.size() - 1; j > sortedPivot; j--) {
// Swap if the value at j is less than the value before it // Swap if the value at j is less than the value before it
if (array[j] < array[j - 1]) { if (array[j] < array[j - 1]) {
std::swap(array[j], array[j - 1]); std::swap(array[j], array[j - 1]);

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of bubble sort using a custom library ## ## About: An example implementation of bubble sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
############################################################################### ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists configuration to practice bucket sort ## ## About: A basic CMakeLists configuration to practice bucket sort ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
@ -9,7 +9,7 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(BucketSort LANGUAGES CXX) project(BucketSort LANGUAGES CXX)
add_executable( add_executable(bucket-sort "bucket-sort.cpp")
algo-sort-bucket bucket-sort.cpp
lib-bucket.cpp lib-bucket.hpp add_library(lib-bucket "lib-bucket.cpp")
) target_link_libraries(bucket-sort lib-bucket)

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of bucket sort using a custom library ## ## About: An example implementation of bucket sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of bucket sort using a custom library ## ## About: An example implementation of bucket sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of bucket sort using a custom library ## ## About: An example implementation of bucket sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
############################################################################### ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists configuration to practice counting sort ## ## About: A basic CMakeLists configuration to practice counting sort ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
@ -9,7 +9,7 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(CountingSort LANGUAGES CXX) project(CountingSort LANGUAGES CXX)
add_executable( add_executable(counting-sort "counting-sort.cpp")
algo-sort-counting counting-sort.cpp
lib-counting.cpp lib-counting.hpp add_library(lib-counting "lib-counting.cpp")
) target_link_libraries(counting-sort lib-counting)

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of counting sort using a custom library ## ## About: An example implementation of counting sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of counting sort using a custom library ## ## About: An example implementation of counting sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
@ -33,19 +33,15 @@ void CountingSort(std::vector<int> &array)
// Count the values less than or equal to each element of tempArray // Count the values less than or equal to each element of tempArray
// + Since each element stores its own count, just add the count at index i-1 // + Since each element stores its own count, just add the count at index i-1
for (int32_t i = 1; i <= maxValue; i++) { for (size_t i = 1; i <= maxValue; i++) {
tempArray[i] += tempArray[i - 1]; tempArray[i] += tempArray[i - 1];
// tempArray[i] - 1 now represents the sorted 0-index pos for each value i
} }
// Step through the array from right-to-left and place each value in their pos
// + As we run into values lookup their position with tempArray[value]
for (ssize_t arrayIndex = array.size() - 1; arrayIndex >= 0; arrayIndex--) { for (ssize_t arrayIndex = array.size() - 1; arrayIndex >= 0; arrayIndex--) {
// Store as references; Changes reflect on actual values within each array
const int &arrayValue = array[arrayIndex]; const int &arrayValue = array[arrayIndex];
// Store as reference; Changes to valueCount reflect within tempArray
int &valueCount = tempArray[arrayValue]; int &valueCount = tempArray[arrayValue];
sortedArray[valueCount - 1] = arrayValue; sortedArray[valueCount - 1] = arrayValue;
// Subtract from tempArray[arrayValue] to update position of next occurrence
valueCount = valueCount - 1; valueCount = valueCount - 1;
} }

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of counting sort using a custom library ## ## About: An example implementation of counting sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -9,8 +9,7 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(HeapSort LANGUAGES CXX) project(HeapSort LANGUAGES CXX)
add_executable( add_executable(heap-sort "heap-sort.cpp")
algo-sort-heap heap-sort.cpp
lib-heap.cpp lib-heap.hpp
)
add_library(lib-heap "lib-heap.cpp")
target_link_libraries(heap-sort lib-heap)

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of heap sort using a custom library ## ## About: An example implementation of heap sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of heap sort using a custom library ## ## About: An example implementation of heap sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
@ -17,7 +17,7 @@ size_t Parent(const size_t &index) { return index / 2;}
size_t Left(const size_t &index) { return 2 * index + 1;} size_t Left(const size_t &index) { return 2 * index + 1;}
size_t Right(const size_t &index) { return (2 * index) + 2;} size_t Right(const size_t &index) { return (2 * index) + 2;}
void MaxHeapify(std::vector<int> &array, size_t thisIndex, const size_t &heapSize) void MaxHeapify(std::vector<int> &array, size_t thisIndex, const int &heapSize)
{ {
// Get an index for the left and right nodes attached to thisIndex // Get an index for the left and right nodes attached to thisIndex
size_t l = Left(thisIndex); size_t l = Left(thisIndex);

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of heap sort using a custom library ## ## About: An example implementation of heap sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
@ -18,7 +18,7 @@ size_t Parent(const size_t &index);
size_t Left(const size_t &index); size_t Left(const size_t &index);
size_t Right(const size_t &index); size_t Right(const size_t &index);
void MaxHeapify(std::vector<int> &array, size_t thisIndex, const size_t &heapSize); void MaxHeapify(std::vector<int> &array, size_t thisIndex, const int &heapSize);
void BuildMaxHeap(std::vector<int> &array); void BuildMaxHeap(std::vector<int> &array);

View File

@ -1,21 +1,15 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists configuration to practice insertion sort ## ## About: A basic CMakeLists configuration to practice insertion sort ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ###############################################################################
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(InsertionSort LANGUAGES CXX)
project ( add_executable(insertion-sort "insertion-sort.cpp")
#[[NAME]] InsertionSort
VERSION 1.0
DESCRIPTION "A project for practicing insertion sort in C++"
LANGUAGES CXX
)
add_executable( add_library(lib-insertion "lib-insertion.cpp")
algo-sort-insertion insertion-sort.cpp target_link_libraries(insertion-sort lib-insertion)
lib-insertion.cpp lib-insertion.hpp
)

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of insertion sort using a custom library ## ## About: An example implementation of insertion sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of insertion sort using a custom library ## ## About: An example implementation of insertion sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
@ -9,13 +9,14 @@
#include "lib-insertion.hpp" #include "lib-insertion.hpp"
#include <algorithm>
#include <vector> #include <vector>
void InsertionSort(std::vector<int> &array) void InsertionSort(std::vector<int> &array)
{ {
// For each value, move left until we find sortedPosition for keyValue // For each value, move left until we find sortedPosition for keyValue
// + Starting with keyValue at array[1], to check sortedPosition at array[0] // + Starting with keyValue at array[1], to check sortedPosition at array[0]
for (size_t keyIndex = 1; keyIndex <= array.size(); keyIndex++) { for (int keyIndex = 1; keyIndex <= array.size(); keyIndex++) {
// Save the current key value // Save the current key value
// + We will look for the sorted position of this value // + We will look for the sorted position of this value
const int keyValue = array[keyIndex]; const int keyValue = array[keyIndex];

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of insertion sort using a custom library ## ## About: An example implementation of insertion sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,21 +1,15 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2020 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists configuration to practice merge sort ## ## About: A basic CMakeLists configuration to practice merge sort ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ###############################################################################
cmake_minimum_required(VERSION 3.17) cmake_minimum_required(VERSION 3.17)
project(MergeSort LANGUAGES CXX)
project ( add_executable(merge-sort "merge-sort.cpp")
#[[NAME]] MergeSort
VERSION 1.0
DESCRIPTION "A project for practicing merge sort in C++"
LANGUAGES CXX
)
add_executable(
algo-sort-merge merge-sort.cpp
lib-merge.cpp lib-merge.h
)
add_library(lib-merge "lib-merge.cpp")
target_link_libraries(merge-sort lib-merge)

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of merge sort using a custom library ## ## About: An example implementation of merge sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of merge sort using a custom library ## ## About: An example implementation of merge sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of merge sort using a custom library ## ## About: An example implementation of merge sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,21 +1,15 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists configuration to practice quick sort ## ## About: A basic CMakeLists configuration to practice quick sort ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ###############################################################################
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(QuickSort LANGUAGES CXX)
project ( add_executable(quick-sort "quick-sort.cpp")
#[[NAME]] QuickSort
VERSION 1.0
DESCRIPTION "A project for practicing quick sort in C++"
LANGUAGES CXX
)
add_executable( add_library(lib-quick "lib-quick.cpp")
algo-sort-quick quick-sort.cpp target_link_libraries(quick-sort lib-quick)
lib-quick.cpp lib-quick.hpp
)

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of quick sort using a custom library ## ## About: An example implementation of quick sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
@ -50,7 +50,7 @@ size_t Partition(std::vector<int> &array, size_t begin, size_t end)
// + Return this value when done, so we know where the lhs partition ends // + Return this value when done, so we know where the lhs partition ends
ssize_t lhsIndex = begin - 1; ssize_t lhsIndex = begin - 1;
// For each value within this partition, check for values < keyValue // For each value within this partition, check for values < keyValue
for (size_t j = begin; j <= end - 1; j++) { for (int j = begin; j <= end - 1; j++) {
if (array[j] <= keyValue) { if (array[j] <= keyValue) {
// Swap all values < keyValue into the lhs portion of array // Swap all values < keyValue into the lhs portion of array
std::swap(array[++lhsIndex], array[j]); std::swap(array[++lhsIndex], array[j]);

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of quick sort using a custom library ## ## About: An example implementation of quick sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of quick sort using a custom library ## ## About: An example implementation of quick sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,22 +1,17 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists configuration to practice radix sort ## ## About: A basic CMakeLists configuration to practice radix sort ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ###############################################################################
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(RadixSort LANGUAGES CXX)
project ( add_executable(radix-sort "radix-sort.cpp")
#[[NAME]] RadixSort
VERSION 1.0
DESCRIPTION "A project for practicing radix sort in C++"
LANGUAGES CXX
)
add_executable( add_library(lib-radix-counting "lib-counting.cpp")
algo-sort-radix radix-sort.cpp add_library(lib-radix "lib-radix.cpp")
lib-counting.cpp lib-counting.hpp
lib-radix.cpp lib-radix.hpp target_link_libraries(radix-sort lib-radix lib-radix-counting)
)

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of counting sort using a custom library ## ## About: An example implementation of counting sort using a custom library ##
## + In support of a radix sort implementation ## ## + In support of a radix sort implementation ##
## ## ## ##
@ -41,7 +41,7 @@ void CountingSort(std::vector<int> &array, int placeValue)
// Count the values less than or equal to each element of tempArray // Count the values less than or equal to each element of tempArray
// + Since each element stores its own count, just add the count at index i-1 // + Since each element stores its own count, just add the count at index i-1
for (size_t i = 1; i < tempArray.size(); i++) { for (int i = 1; i < tempArray.size(); i++) {
tempArray[i] = tempArray[i] + tempArray[i - 1]; tempArray[i] = tempArray[i] + tempArray[i - 1];
} }

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of counting sort using a custom library ## ## About: An example implementation of counting sort using a custom library ##
## + In support of a radix sort implementation ## ## + In support of a radix sort implementation ##
## ## ## ##

View File

@ -1,11 +1,3 @@
/*#############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: An example implementation of radix sort using a custom library ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
###############################################################################
*/
#include "lib-radix.hpp" #include "lib-radix.hpp"
#include "lib-counting.hpp" #include "lib-counting.hpp"

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of radix sort using a custom library ## ## About: An example implementation of radix sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of radix sort using a custom library ## ## About: An example implementation of radix sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,21 +1,15 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists configuration to practice selection sort ## ## About: A basic CMakeLists configuration to practice selection sort ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ###############################################################################
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(SelectionSort LANGUAGES CXX)
project ( add_executable(select-sort "select-sort.cpp")
#[[NAME]] SelectionSort
VERSION 1.0
DESCRIPTION "A project for practicing selection sort in C++"
LANGUAGES CXX
)
add_executable( add_library(lib-select "lib-select.cpp")
algo-sort-select select-sort.cpp target_link_libraries(select-sort lib-select)
lib-select.cpp lib-select.h
)

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of selection sort using a custom library ## ## About: An example implementation of selection sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
@ -12,10 +12,10 @@
#include <vector> #include <vector>
void SelectionSort(std::vector<int> &arr) { void SelectionSort(std::vector<int> &arr) {
for (size_t leftIndex = 0; leftIndex < arr.size(); leftIndex++) { for (int leftIndex = 0; leftIndex < arr.size(); leftIndex++) {
// Get the index for the minimum number in the unsorted set // Get the index for the minimum number in the unsorted set
size_t min = leftIndex; int min = leftIndex;
for (size_t i = leftIndex; i < arr.size(); i++) { for (int i = leftIndex; i < arr.size(); i++) {
// Check if value at i is smaller than value at min index // Check if value at i is smaller than value at min index
min = (arr[min] > arr[i]) ? i : min; // Update min value to i if true min = (arr[min] > arr[i]) ? i : min; // Update min value to i if true
} }

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of selection sort using a custom library ## ## About: An example implementation of selection sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example implementation of selection sort using a custom library ## ## About: An example implementation of selection sort using a custom library ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,11 +1,11 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A root project for practicing algorithms in C++ ## ## About: A root project for practicing algorithms in C++ ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( project (

View File

@ -1,11 +1,11 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists configuration to test BST implementation ## ## About: A basic CMakeLists configuration to test BST implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( project (
@ -15,7 +15,7 @@ project (
LANGUAGES CXX LANGUAGES CXX
) )
add_executable( add_library(lib-bst-algo "bst.cpp")
algo-trees-bst driver.cpp
bst.cpp bst.h add_executable(test-bst-algo "driver.cpp")
) target_link_libraries(test-bst-algo lib-bst-algo)

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a binary search tree implementation ## ## About: An example of a binary search tree implementation ##
## The algorithms in this example are seen in MIT Intro to Algorithms ## ## The algorithms in this example are seen in MIT Intro to Algorithms ##
## ## ## ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a binary search tree implementation ## ## About: An example of a binary search tree implementation ##
## The algorithms in this example are seen in MIT Intro to Algorithms ## ## The algorithms in this example are seen in MIT Intro to Algorithms ##
## ## ## ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: Driver program to test BST algorithms from MIT intro to algorithms ## ## About: Driver program to test BST algorithms from MIT intro to algorithms ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,11 +1,11 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists configuration to test RBT implementation ## ## About: A basic CMakeLists configuration to test RBT implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( project (
@ -15,7 +15,7 @@ project (
LANGUAGES CXX LANGUAGES CXX
) )
add_executable( add_library(lib-redblack "redblack.cpp")
algo-trees-redblack driver.cpp
redblack.cpp redblack.h add_executable(test-redblack "driver.cpp")
) target_link_libraries(test-redblack lib-redblack)

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: Driver program to test RBT algorithms from MIT intro to algorithms ## ## About: Driver program to test RBT algorithms from MIT intro to algorithms ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a red-black tree implementation ## ## About: An example of a red-black tree implementation ##
## The algorithms in this example are seen in MIT Intro to Algorithms ## ## The algorithms in this example are seen in MIT Intro to Algorithms ##
## ## ## ##

View File

@ -1,6 +1,6 @@
/*############################################################################# /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a red black tree implementation ## ## About: An example of a red black tree implementation ##
## The algorithms in this example are seen in MIT Intro to Algorithms ## ## The algorithms in this example are seen in MIT Intro to Algorithms ##
## ## ## ##

View File

@ -1,31 +0,0 @@
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Practice project for testing with catch2 framework ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Catch2
VERSION 1.0
DESCRIPTION "Practice project for learning Catch2"
LANGUAGES CXX
)
add_compile_options(-Wall)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.0.1
)
FetchContent_MakeAvailable(Catch2)
add_subdirectory(src)
add_subdirectory(test)

View File

@ -1,10 +0,0 @@
#ifndef KLIPS_KLIPS_H
#define KLIPS_KLIPS_H
class klips { };
unsigned int factorial(unsigned int);
#endif // KLIPS_KLIPS_H

View File

@ -1,29 +0,0 @@
// Authored by 康桓瑋 on SO: https://stackoverflow.com/a/56766138
#ifndef CATCH2_TYPE_NAME_HPP
#include <string_view>
template <typename T>
constexpr auto type_name() {
std::string_view name, prefix, suffix;
#ifdef __clang__
name = __PRETTY_FUNCTION__;
prefix = "auto type_name() [T = ";
suffix = "]";
#elif defined(__GNUC__)
name = __PRETTY_FUNCTION__;
prefix = "constexpr auto type_name() [with T = ";
suffix = "]";
#elif defined(_MSC_VER)
name = __FUNCSIG__;
prefix = "auto __cdecl type_name<";
suffix = ">(void)";
#endif
name.remove_prefix(prefix.size());
name.remove_suffix(suffix.size());
return name;
}
#define CATCH2_TYPE_NAME_HPP
#endif // CATCH2_TYPE_NAME_HPP

View File

@ -1,22 +0,0 @@
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Practice project for testing with catch2 framework ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Catch2
VERSION 1.0
DESCRIPTION "Practice project for learning Catch2"
LANGUAGES CXX
)
add_compile_options(-Wall)
add_definitions("-std=c++17")
add_library(klips SHARED klips.cpp)
target_include_directories(klips PRIVATE ${CMAKE_SOURCE_DIR}/include)

View File

@ -1,4 +0,0 @@
unsigned int factorial( unsigned int number ) {
return number <= 1 ? number : factorial(number-1)*number;
}

View File

@ -1,22 +0,0 @@
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Practice project for testing with catch2 framework ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Catch2
VERSION 1.0
DESCRIPTION "Practice project for learning Catch2"
LANGUAGES CXX
)
add_compile_options(-Wall)
add_executable(test_klips test_klips.cpp)
target_link_libraries(test_klips PRIVATE Catch2::Catch2WithMain klips)
target_include_directories(test_klips PRIVATE ${CMAKE_SOURCE_DIR}/include)

View File

@ -1,147 +0,0 @@
#define CATCH_CONFIG_MAIN
#include <iostream>
#include "../bin/catch.hpp"
#include "klips.hpp"
#include "type_name.hpp"
#define TT() std::cout << "T = " << type_name<TestType>() << std::endl;
#define TD(x) \
std::cout << type_name<decltype(x)>() << " " << #x << " = " << x << std::endl;
#define T(x) std::cout << "T = " << type_name<x>() << std::endl;
TEST_CASE("factorials are computed", "[factorial]") {
REQUIRE(factorial(1) == 1);
REQUIRE(factorial(2) == 2);
REQUIRE(factorial(3) == 6);
REQUIRE(factorial(10) == 3628800);
}
TEST_CASE("Generators") {
auto i = GENERATE(1, 3, 5);
TD(i);
}
TEST_CASE("Generators 2") {
auto i = GENERATE(1, 2);
SECTION("one") {
auto j = GENERATE(-3, -2);
REQUIRE(j < i);
std::cout << "i = " << i << "; j = " << j << std::endl;
}
SECTION("two") {
auto k = GENERATE(4, 5, 6);
REQUIRE(i != k);
std::cout << "i = " << i << "; k = " << k << std::endl;
}
}
TEST_CASE("Complex mix of sections and generates") {
auto i = GENERATE(1, 2);
SECTION("A") {
std::cout << "i = " << i << "; A passed" << std::endl;
SUCCEED("A");
}
std::cout << "left A\n";
auto j = GENERATE(3, 4);
std::cout << "i = " << i << "; j = " << j << std::endl;
SECTION("B") {
std::cout << "i = " << i << "; j = " << j << "; B passed;" << std::endl;
SUCCEED("B");
}
auto k = GENERATE(5, 6);
std::cout << "i = " << i << "; k = " << k << std::endl;
SUCCEED();
}
TEST_CASE("Test generaators 3", "[test]") { GENERATE(values({1, 2})); }
TEMPLATE_TEST_CASE("Testing template tests", "[test][template]", int8_t,
int16_t, int32_t, int64_t) {
TT();
}
template <typename T> struct Foo {
size_t size() { return 0; }
};
template <typename T> struct Test {
T test() {
T x;
return x;
}
};
TEMPLATE_PRODUCT_TEST_CASE("A Template product test case",
"[template][product]", (std::vector, Test),
(int, float)) {
TT();
}
TEMPLATE_PRODUCT_TEST_CASE("Product with differing arities",
"[template][product]", std::tuple,
(int, (int, double), (int, double, float))) {
TT();
}
using types = std::tuple<int8_t, int16_t, int32_t, int64_t>;
TEMPLATE_LIST_TEST_CASE("Testing template list tests", "[test][template][list]",
types) {
TT();
}
TEMPLATE_TEST_CASE_SIG(
"TemplateTestSig: arrays can be created from NTTP arguments",
"[vector][template][nttp]", ((typename T, int V), T, V), (int, 5),
(float, 4), (std::string, 15), ((std::tuple<int, float>), 6)) {
T(T);
std::cout << "V = " << V;
std::array<T, V> v;
REQUIRE(v.size() > 1);
}
template <typename T, size_t S> struct Bar {
size_t size() { return S; }
};
TEMPLATE_PRODUCT_TEST_CASE_SIG(
"A Template product test case with array signature",
"[template][product][nttp]", ((typename T, size_t S), T, S),
(std::array, Bar), ((int, 9), (float, 42))) {
TT();
TestType x;
REQUIRE(x.size() > 0);
}
template <typename T> struct test_config_get {
template <bool must_find> void run() {
// Config c{};
// std::string key{"the_key"};
// std::string value{"the_value"};
// c.set(key, value);
if constexpr (must_find) {
std::cout << "Test 1 ran";
} else {
std::cout << "Test 2 ran";
}
}
};
template <> template <bool must_find> void test_config_get<std::string>::run() {
if constexpr (must_find) {
std::cout << "Test 1 ran for strings";
} else {
std::cout << "Test 2 ran for strings";
}
}
TEMPLATE_PRODUCT_TEST_CASE("Test", "[test]", test_config_get,
(int, std::string)) {
TT();
TestType t;
test_config_get<int> s;
s.template run<true>();
// TestType t;
// t.run<true>();
}

View File

@ -1,27 +1,19 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A template project for getting started working with CMake ## ## About: A template project for getting started working with CMake ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
# Define the version of CMake # Define the version of CMake
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
# CMake options
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Compiler options
add_compile_options("-Wall")
# Define the your project name # Define the your project name
project ( project(cmake-template)
#[[NAME]] CMakeTemplate
VERSION 1.0
DESCRIPTION "A basic CMake template for C++ projects"
LANGUAGES CXX
)
# Include any directories the compiler may need # Include any directories the compiler may need
include_directories(./include) include_directories(./include)

View File

@ -1,16 +1,17 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
## This directory is for storing / compiling our executable code ## This directory is for storing / compiling our executable code
# Create a reference / variable to refer to our source code # Create a reference / variable to refer to our source code
set(APP_SRC say-hello.cpp) set(APP_SRC say-hello.cpp)
# Add our executable, naming it and linking it to our source code # Add our executable, naming it and linking it to our source code
add_executable(cmake-example-template ${APP_SRC}) add_executable(execute-hello ${APP_SRC})
# Link to our custom library, defined in c-cmake/src/ # Link to our custom library, defined in c-cmake/src/
target_link_libraries(cmake-example-template cmake-example-lib) target_link_libraries(execute-hello lib-klips)

View File

@ -1,12 +1,12 @@
/*############################################################################## /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2019 Shaun Reed, all rights reserved ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
*/ */
#include <lib-example.hpp> #include <lib-klips.hpp>
#include <iostream> #include <iostream>
int main () { int main () {

View File

@ -1,9 +1,9 @@
/*############################################################################## /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2019 Shaun Reed, all rights reserved ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
*/ */
/** /**

View File

@ -1,13 +1,14 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
## This directory is for storing source code ## This directory is for storing source code
# Create any links we might need # Create any links we might need
set(LIB_SRC lib-example.cpp) set(LIB_SRC lib-klips.cpp)
# Define our library within CMake and link to the source code # Define our library within CMake and link to the source code
add_library(cmake-example-lib ${LIB_SRC}) add_library(lib-klips ${LIB_SRC})

View File

@ -1,12 +1,12 @@
/*############################################################################## /*#############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2019 Shaun Reed, all rights reserved ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
*/ */
#include <lib-example.hpp> #include <lib-klips.hpp>
#include <iostream> #include <iostream>
void PrintHello(int n) { void PrintHello(int n) {

View File

@ -1,11 +1,11 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A root project for practicing cryptography in C++ ## ## About: A root project for practicing cryptography in C++ ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( project (

View File

@ -5,6 +5,7 @@
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ################################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
@ -15,7 +16,7 @@ project(
LANGUAGES CXX LANGUAGES CXX
) )
add_executable( add_library(lib-cipher "lib-cipher.cpp")
crypto-columnar-transposition driver.cpp
lib-cipher.cpp lib-cipher.hpp add_executable(columnar-transposition-test "driver.cpp")
) target_link_libraries(columnar-transposition-test lib-cipher)

View File

@ -21,9 +21,9 @@ void Columnar::InitOrder(std::string temp)
temp.erase(it, temp.end()); temp.erase(it, temp.end());
// Step through each character in lexicographic order // Step through each character in lexicographic order
for (size_t i = 0; i < temp.size(); i++) { for (int i = 0; i < temp.size(); i++) {
// Check each character in the keyWord for the current lexicographic char // Check each character in the keyWord for the current lexicographic char
for (size_t j = 0; j < keyWord_.size(); j++) { for (int j = 0; j < keyWord_.size(); j++) {
// If they are equal, push the index of the char in keyWord to orderVect // If they are equal, push the index of the char in keyWord to orderVect
if (keyWord_[j] == temp[i]) { if (keyWord_[j] == temp[i]) {
orderVect_.push_back(j); orderVect_.push_back(j);
@ -109,7 +109,7 @@ std::string Columnar::Decrypt(std::string message)
rows.resize(orderVect_.size()); rows.resize(orderVect_.size());
// Track the ending position after each substring is taken // Track the ending position after each substring is taken
int lastPos = 0; int lastPos = 0;
for (size_t i = 0; i < orderVect_.size(); i++) { for (int i = 0; i < orderVect_.size(); i++) {
// If we are assigning to any row < fullRows, it should have + 1 character // If we are assigning to any row < fullRows, it should have + 1 character
if (orderVect_[i] < fullRows) { if (orderVect_[i] < fullRows) {
rows[orderVect_[i]] = message.substr(lastPos, rowLength + 1); rows[orderVect_[i]] = message.substr(lastPos, rowLength + 1);

View File

@ -1,11 +1,11 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A root project for practicing C++ data structure implementations ## ## About: A root project for practicing C++ data structure implementations ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( project (

View File

@ -1,11 +1,11 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A basic CMakeLists configuration to test BST implementation ## ## About: A basic CMakeLists configuration to test BST implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( project (
@ -15,7 +15,7 @@ project (
LANGUAGES CXX LANGUAGES CXX
) )
add_executable( add_library(lib-bst "bst.cpp")
data-bst driver.cpp
bst.cpp bst.h add_executable(test-bst "driver.cpp")
) target_link_libraries(test-bst lib-bst)

View File

@ -1,21 +1,16 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a circular doubly linked list implementation ## ## About: An example of a circular doubly linked list implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( # Define the project name
#[[NAME]] CircleDoubleList project(CircleDouble)
VERSION 1.0 # Define source files
DESCRIPTION "Project for testing circular doubly linked list implementation" set(SRC driver.cpp circledoublelist.cpp)
LANGUAGES CXX # Build an executable
) add_executable(CircleDoubleDriver ${SRC})
add_executable(
data-circular-doubly-linked-list driver.cpp
circledoublelist.cpp circledoublelist.h
)

View File

@ -1,21 +1,16 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a circular singly linked list implementation ## ## About: An example of a circular singly linked list implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( # Define the project name
#[[NAME]] CircleSingleList project(CircleSingle)
VERSION 1.0 # Define source files
DESCRIPTION "Project for testing circular singly linked list implementation" set(SRC driver.cpp circlesinglelist.cpp)
LANGUAGES CXX # Build an executable
) add_executable(CircleSingleDriver ${SRC})
add_executable(
data-circular-singly-linked-list driver.cpp
circlesinglelist.cpp circlesinglelist.h
)

View File

@ -1,21 +1,16 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a doubly linked list implementation ## ## About: An example of a doubly linked list implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( # Define the project name
#[[NAME]] DoubleList project(DoubleList)
VERSION 1.0 # Define source files
DESCRIPTION "A project for testing a doubly linked list implementation" set(SRC driver.cpp doublelist.cpp)
LANGUAGES CXX # Build an executable
) add_executable(DoubleListDriver ${SRC})
add_executable(
data-doubly-linked-list driver.cpp
doublelist.cpp doublelist.h
)

View File

@ -1,21 +1,16 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a max heap implementation ## ## About: An example of a max heap implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( # Define the project name
#[[NAME]] MaxHeap project(MaxHeap)
VERSION 1.0 # Define source files
DESCRIPTION "A project for testing a max heap implementation" set(SRC driver.cpp maxheap.cpp)
LANGUAGES CXX # Build an executable
) add_executable(HeapDriver ${SRC})
add_executable(
data-max-heap driver.cpp
maxheap.cpp maxheap.h
)

View File

@ -1,21 +1,16 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a queue implementation ## ## About: An example of a queue implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( # Define the project name
#[[NAME]] Queue project(Queue)
VERSION 1.0 # Define source files
DESCRIPTION "Project for testing queue implementation" set(SRC driver.cpp queuelist.cpp)
LANGUAGES CXX # Build an executable
) add_executable(QueueDriver ${SRC})
add_executable(
data-queue driver.cpp
queuelist.cpp queuelist.h
)

View File

@ -1,21 +1,16 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a singly linked list implementation ## ## About: An example of a singly linked list implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( # Define the project name
#[[NAME]] SingleList project(SingleList)
VERSION 1.0 # Define source files
DESCRIPTION "A project for testing a singly linked list implementation" set(SRC driver.cpp singlelist.cpp)
LANGUAGES CXX # Build an executable
) add_executable(SingleListDriver ${SRC})
add_executable(
data-singly-linked-list driver.cpp
singlelist.cpp singlelist.h
)

View File

@ -1,21 +1,17 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a stack implementation using linked lists ## ## About: An example of a stack implementation using linked lists ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
## CMakeLists.txt
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( # Define the project name
#[[NAME]] Stack project(Stack)
VERSION 1.0 # Define source files
DESCRIPTION "A project for testing a Stack implementation" set(SRC driver.cpp stacklist.cpp)
LANGUAGES CXX # Build an executable
) add_executable(StackDriver ${SRC})
add_executable(
data-stack driver.cpp
stacklist.cpp stacklist.h
)

View File

@ -1,11 +1,11 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A root project for practicing templated data structures in C++ ## ## About: A root project for practicing templated data structures in C++ ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( project (

View File

@ -1,18 +1,16 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a templated doubly linked list implementation ## ## About: An example of a doubly linked list implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( # Define the project name
#[[NAME]] TemplatedDoubleList project(DoubleList)
VERSION 1.0 # Define source files
DESCRIPTION "A project for practicing templated doubly linked list implementations" set(SRC driver.cpp)
LANGUAGES CXX # Build an executable
) add_executable(TemplatedDoubleListDriver ${SRC})
add_executable(data-templates-doubly-linked-list driver.cpp)

View File

@ -1,18 +1,16 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a templated queue implementation ## ## About: An example of a queue implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( # Define the project name
#[[NAME]] TemplatedQueue project(Queue)
VERSION 1.0 # Define source files
DESCRIPTION "A project for practicing templated queue implementations" set(SRC driver.cpp)
LANGUAGES CXX # Build an executable
) add_executable(TemplatedQueueDriver ${SRC})
add_executable(data-templates-queue driver.cpp)

View File

@ -1,18 +1,16 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a templated stack implementation using linked lists ## ## About: An example of a stack implementation using linked lists ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( # Define the project name
#[[NAME]] TemplatedStack project(Stack)
VERSION 1.0 # Define source files
DESCRIPTION "A project for practicing templated Stack implementations" set(SRC driver.cpp)
LANGUAGES CXX # Build an executable
) add_executable(TemplatedStackDriver ${SRC})
add_executable(data-templates-stack driver.cpp)

View File

@ -1,18 +1,17 @@
################################################################################ ###############################################################################
## Author: Shaun Reed ## ## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ## ## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: An example of a templated vector implementation ## ## About: A basic CMakeLists configuration to test Vector implementation ##
## ## ## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################ ##############################################################################
## vector.cpp
#
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project ( # Define the project name
#[[NAME]] TemplatedVector project(VectorDriver)
VERSION 1.0 # Define source files
DESCRIPTION "A project for practicing templated Vector implementations" set(SRC driver.cpp)
LANGUAGES CXX # Build an executable
) add_executable(TemplatedVectorDriver ${SRC})
add_executable(data-templates-vectors driver.cpp)

Some files were not shown because too many files have changed in this diff Show More