D
D
DenNewGit2018-03-26 09:20:44
Delphi
DenNewGit, 2018-03-26 09:20:44

How to write visualization of sorting algorithm in delphi?

It is necessary to visualize the sorting algorithm by the method of simple insertions

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2018-03-26
@Mercury13

longclaps wrote how the whole thing should look externally.
Internally this is easy to do.
1. In the OnPaint of some component (PaintBox, say), under certain conditions, we display the visualization.
2. We block the entire user interface (except for some "Stop" button).
3. Every time we need to see something, we do paintBox.Repaint, Application.ProcessMessages and a short delay.
4. When you click the "Stop" button, set some variable to true. The sort reacts to this variable and stops the loop, either with a simple Exit, or with an Abort crash and a subsequent reaction to EAbort.
If you want to compare several sorting algorithms, you should make a function like DoSwap(i, j : integer) that swaps elements, sets everything that is needed for rendering, initiates a redraw and makes a delay.

A
Alexander Skusnov, 2018-03-26
@AlexSku

In the Demos\Threads folder there is an example of rendering three sorts in parallel. 5ab9244301736225194965.png
This is a speed comparison.
Or do you need more visibility? Here are examples of dances.
https://forany.xyz/a-370

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question