Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
greedy_algorithms Namespace Reference

for std::vector More...

Namespaces

namespace  dijkstra
 Functions for the Dijkstra algorithm implementation.
 

Functions

bool can_jump (const std::vector< int > &nums)
 Checks whether the given element (default is 1) can jump to the last index.
 
template<typename T >
void findMinimumEdge (const int &infinity, const std::array< std::array< T, 6 >, 6 > &graph)
 Finds the minimum edge of the given graph.
 

Detailed Description

for std::vector

for IO operations

for assert for INT_MAX for IO operations

Greedy Algorithms

for assert for std::cout

Greedy Algorithms

for array

Greedy Algorithms

Function Documentation

◆ can_jump()

bool greedy_algorithms::can_jump ( const std::vector< int > & nums)

Checks whether the given element (default is 1) can jump to the last index.

Parameters
numsarray of numbers containing the maximum jump (in steps) from that index
Returns
true if the index can be reached
false if the index can NOT be reached
42 {
43 size_t lastPos = nums.size() - 1;
44 for (size_t i = lastPos; i != static_cast<size_t>(-1); i--) {
45 if (i + nums[i] >= lastPos) {
46 lastPos = i;
47 }
48 }
49 return lastPos == 0;
50}
T size(T... args)
Here is the call graph for this function:

◆ findMinimumEdge()

template<typename T >
void greedy_algorithms::findMinimumEdge ( const int & infinity,
const std::array< std::array< T, 6 >, 6 > & graph )

Finds the minimum edge of the given graph.

Parameters
infinityDefines the infinity of the graph
graphThe graph that will be used to find the edge
Returns
void
37 {
38 for (int i = 0; i < graph.size(); i++) {
39 int min = infinity;
40 int minIndex = 0;
41 for (int j = 0; j < graph.size(); j++) {
42 if (graph[i][j] != 0 && graph[i][j] < min) {
43 min = graph[i][j];
44 minIndex = j;
45 }
46 }
47 std::cout << i << " - " << minIndex << "\t" << graph[i][minIndex]
48 << "\n";
49 }
50}
Graph Algorithms.