TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
backtracking Namespace Reference

for vector container More...

Classes

class  generate_parentheses
 generate_parentheses class More...
 

Functions

template<size_t T>
int minimax (int depth, int node_index, bool is_max, const std::array< int, T > &scores, double height)
 Check which is the maximum/minimum number in the array.
 

Detailed Description

for vector container

for assert

Backtracking algorithms.

for IO operations

for std::vector

for assert for I/O operation

Backtracking algorithms

for std::array for IO operations

Backtracking algorithms

for std::array

Backtracking algorithms

for std::count for assert for IO operations for std::list for std::accumulate for std::vector

for std::max, std::min for std::array for log2

Backtracking algorithms

for std::array for assert

Backtracking algorithms

for IO operations for unordered_map for std::vector

Backtracking algorithms

for IO operations for std::vector

Backtracking algorithms

for assert

Backtracking algorithms

Function Documentation

◆ minimax()

template<size_t T>
int backtracking::minimax ( int depth,
int node_index,
bool is_max,
const std::array< int, T > & scores,
double height )

Check which is the maximum/minimum number in the array.

Parameters
depthcurrent depth in game tree
node_indexcurrent index in array
is_maxif current index is the longest number
scoressaved numbers in array
heightmaximum height for game tree
Returns
the maximum or minimum number

Definition at line 39 of file minimax.cpp.

40 {
41 if (depth == height) {
42 return scores[node_index];
43 }
44
45 int v1 = minimax(depth + 1, node_index * 2, !is_max, scores, height);
46 int v2 = minimax(depth + 1, node_index * 2 + 1, !is_max, scores, height);
47
48 return is_max ? std::max(v1, v2) : std::min(v1, v2);
49}
int height(node *root)
Definition avltree.cpp:38