ALGO-VISUALIZER DOCUMENTATION πŸ”₯

Below is the documentation for the algo-visualizer project. The project is a tool to visualize the execution of algorithms, specifically sorting algorithms. The visualizer is written in C++ and uses the SFML library for rendering.

visualizer Namespace

This is the documentation for the classes and functions in the visualizer namespace.

namespace visualizer

Enums

enum AppState

Enum class to represent the different states of the application.

WELCOME_SCREEN: The screen that is displayed when the application is started SELECTION_SCREEN: The screen that is displayed when the user selects the sorting algorithm RUNNING: The screen that displays the sorting process COMPLETION: The screen that is displayed when the sorting process is complete EXIT: The state that is reached when the application is closed

Values:

enumerator WELCOME_SCREEN
enumerator SELECTION_SCREEN
enumerator RUNNING
enumerator COMPLETION
enumerator EXIT
class SortVisualizer : public visualizer::Visualizer<std::vector<int>>
#include <visualizer.h>

Class for visualizing sorting algorithms.

Note

Inherits from the Visualizer class

Public Functions

SortVisualizer(int width, int height, int size, int speed)

Construct a new Sort Visualizer object.

Parameters:
  • width – The width of the window

  • height – The height of the window

  • size – The size of the array to sort

  • speed – The speed of the visualization

SortVisualizer(int width, int height, int size, int speed, std::string heading)

Construct a new Sort Visualizer object.

Parameters:
  • width – The width of the window

  • height – The height of the window

  • size – The size of the array to sort

  • speed – The speed of the visualization

  • heading – The heading of the window

SortVisualizer(int width, int height, int size, int speed, std::string heading, std::string timeComplexity)

Construct a new Sort Visualizer object.

Parameters:
  • width – The width of the window

  • height – The height of the window

  • size – The size of the array to sort

  • speed – The speed of the visualization

  • heading – The heading of the window

  • timeComplexity – The time complexity of the algorithm

virtual void addState(const std::vector<int> &array) override

Add a new state (array configuration) to be visualized.

Note

Overrides the addState method of the Visualizer class

Parameters:

array – The array to add

Returns:

void

virtual void visualize() override

Visualize the algorithm.

Note

Overrides the visualize method of the Visualizer class

Returns:

void

template<typename Container>
class Visualizer
#include <visualizer.h>

Abstract class for visualizing algorithms.

Template Parameters:

Container – The type of the data structure to visualize

Public Functions

Visualizer(int width, int height, int speed, std::string heading)

Construct a new Visualizer object.

Parameters:
  • width – The width of the window

  • height – The height of the window

  • speed – The speed of the visualization

  • heading – The heading of the window

virtual void addState(const Container &array) = 0

Add a new state (array configuration) to be visualized.

Note

Pure virtual function

Parameters:

array – The array to add

Returns:

void

virtual void visualize() = 0

Visualize the algorithm.

Note

Pure virtual function

Returns:

void

algorithm Namespace

This is the documentation for the classes and functions in the algorithm namespace.

namespace algorithm

Enums

enum class SortType

Enum class to represent the different sorting algorithms.

Values:

enumerator UNINITIALIZED
enumerator SELECTION
enumerator BUBBLE
enumerator INSERTION
enumerator MERGE
enumerator QUICK
enumerator BOGO
enumerator STD

Functions

void randomNumberGen(std::vector<int> &arr, int size, int min, int max)
void selectionSort(std::vector<int> &arr, std::function<void(const std::vector<int>&)> stepCallback = [](const std::vector< int > &) {})

Sorts the given array using the selection sort algorithm.

Parameters:
  • arr – The array to sort

  • stepCallback – lambda function to call after each step letting the caller know the current state of the array

void bubbleSort(std::vector<int> &arr, std::function<void(const std::vector<int>&)> stepCallback = [](const std::vector< int > &) {})

Sorts the given array using the bubble sort algorithm.

Parameters:
  • arr – The array to sort

  • stepCallback – lambda function to call after each step letting the caller know the current state of the array

void insertionSort(std::vector<int> &arr, std::function<void(const std::vector<int>&)> stepCallback = [](const std::vector< int > &) {})

Sorts the given array using the insertion sort algorithm.

Parameters:
  • arr – The array to sort

  • stepCallback – lambda function to call after each step letting the caller know the current state of the array

void iterMergeSort(std::vector<int> &arr, std::function<void(const std::vector<int>&)> stepCallback)
void iterQuickSort(std::vector<int> &arr, std::function<void(const std::vector<int>&)> stepCallback)
void mergeSort(std::vector<int> &arr, std::function<void(const std::vector<int>&)> stepCallback = [](const std::vector< int > &) {})

Sorts the given array using the merge sort algorithm.

Parameters:
  • arr – The array to sort

  • stepCallback – lambda function to call after each step letting the caller know the current state of the array

void quickSort(std::vector<int> &arr, std::function<void(const std::vector<int>&)> stepCallback = [](const std::vector< int > &) {})

Sorts the given array using the quick sort algorithm.

Parameters:
  • arr – The array to sort

  • stepCallback – lambda function to call after each step letting the caller know the current state of the array

void bogoSort(std::vector<int> &arr, std::function<void(const std::vector<int>&)> stepCallback = [](const std::vector< int > &) {})

Sorts the given array using the bogo sort algorithm.

Note

This algorithm won’t work for large arrays as the time complexity is infinity in the worst case. For the application of this visualizer, it will not work as the sorting is recquired to be finished before visualizing the steps.

Parameters:
  • arr – The array to sort

  • stepCallback – lambda function to call after each step letting the caller know the current state of the array

algo_resources Namespace

This is the documentation for the classes and functions in the algo_resources namespace.

Warning

doxygennamespace: Cannot find namespace β€œalgo_resources” in doxygen xml output for project β€œALGO-VISUALIZER” from directory: /home/docs/checkouts/readthedocs.org/user_builds/algo-visualizer/checkouts/latest/docs/source/../../build/docs/doxygen/xml