There is a more general methodology for writing algorithms, the following steps:
1. Understanding the problem
Let's figure out what the problem is.
2, analysis of the problem
What is the extent to which the problem needs to be met? Do you need an exact value or an approximate value?
3. Determine the appropriate data structure
4. Using pseudo-code to express the algorithm
This is a crucial step, basically a step in determining success or failure.
The purpose of pseudo-code is to guide the implementation of the final code, so it is clearly structured and readable.
Pseudo-code focuses on describing the execution of the algorithm, ignoring details such as variable type, partial sub-functions (such as removing the smallest element in the array, etc.) implementation.
5. Thinking about algorithm correctness and efficiency
6. Coding the final code
How to write algorithms?