# Algorithms_in_C++: backtracking Namespace Reference

Loading...
Searching...
No Matches
backtracking Namespace Reference

for std::vector 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. More...

## Detailed Description

for std::vector

Backtracking algorithms.

for IO operations

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

Backtracking algorithms

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

Backtracking algorithms

for std::array for assert

Backtracking algorithms

for assert for IO operations for unordered_map

Backtracking algorithms

for assert for IO operations

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

  depth | current depth in game tree
  node_index | current index in array
  is_max | if current index is the longest number
  scores | saved numbers in array
  height | maximum height for game tree

Returns
  the maximum or minimum number

{
if (depth == height) {
return scores[node_index];
}
int v1 = minimax(depth + 1, node_index * 2, !is_max, scores, height);
int v2 = minimax(depth + 1, node_index * 2 + 1, !is_max, scores, height);
return is_max ? std::max(v1, v2) : std::min(v1, v2);
}
height
int height(node *root)
Definition: avltree.cpp:31
std::max
T max(T... args)
std
STL namespace.
Here is the call graph for this function: