# Merge sort

### Sort a vector using merge sort:

```cpp
mergeSort(arr, isAscending);
```

returns the sorted vector arr, based on provided isAscending condition (`true` for ascending and `false` for descending).

### Example use case:

Running

```cpp
std::vector<int> arr= {5, 2, 9, 1, 5, 6};

std::cout << "Original Vector: ";
for(int num : arr){
    std::cout << num << " ";
}    
std::cout << std::endl;

mergeSort(arr, true);

std::cout << "Sorted Ascending Vector: ";
for(int num : arr){
    std::cout << num << " ";
}
std::cout << std::endl;
```

, returns the following output:

```
Original Vector: 5 2 9 1 5 6 
Sorted Ascending Vector: 1 2 5 5 6 9 
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://math-5.gitbook.io/math/reference/algorithms/merge-sort.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
