Sort viewer is a React application that helps to understand sorting algorithms by simulating and visualizing them.
The visualization includes showing which elements are currently being checked and which is going to be swapped, pivot (in quick sort), etc...
The sorting is customizable, you can control the array size and thg sort speed.
You can also can view and navigate between each sort step.
After the user choose clicks on sort, the algorithm is creating an array with sorting steps,
each sorting step contain the following information:
-
array - the current state of the array
-
colorMapping - an object that contains indices as
keys
and type of color asvalues
.
for example:// color mapping when checking two elements: const colorMappingChecking = { 0: "CHECK", 1: "CHECK", }; // color mapping when swapping two elements: const colorMappingSwapping = { 0: "SWAPPING", 1: "SWAPPING", }; // color mapping with pivot (quick sort): const colorMappingWithPivot = { 0: "CHECK", 1: "CHECK", 2: "PIVOT", };
-
permanentColorMapping - an object that represent colored indices that should be always be presented, they have 'higher priority' then colorMapping object
A complete sort step looks like this:
const step = {
// each element each have id because of swap array elements animation
array: [
{ id: "1", number: 3 },
{ id: "2", number: 1 },
{ id: "3", number: 2 },
],
colorMapping: {
0: "CHECK",
1: "CHECK",
},
permanentColorMapping: {
2: "SORTED",
},
};
After that between each delay
that the user chose, each step is being rendered to the screen,
element that needs to be colored, will be colored according to the color mappings (colorMapping, permanentColorMapping)
.
Clone the project:
$ git clone https://github.com/Yitzhakpro/Sort-Viewer.git
Install the dependencies:
$ yarn
Run dev:
$ yarn dev