Using pointers to implement bubble sort in C#

Anyone who uses Vs knows that C# cannot use pointers but when we mark a code block with the unsafe modifier, C# allows the use of pointer variables in functions. Unsafe code or unmanaged code is a block of code that uses pointer variables.

A pointer is a variable whose value is the address of another variable, that is, the direct address of a memory location. Just like other variables or constants, you must declare pointers before using pointers to store addresses of other variables. Bubbling is the first contact sequence for beginners to learn C# programming. Although it is not often used in the workplace, those who learn programming also need to understand how to achieve it.

1. The principle of first bubbling is that two values ​​are relatively close, and the larger value is placed in the back until a value larger than it is encountered.
2. The following figure is a schematic diagram of the principle of bubbling


3. Gossip less and see examples:


4. Call in the Main function:


There is so much code, I hope it will be helpful to the viewers. The main reason for the bad writing is sharing. I hope everyone can point out the faults! ! ! help each other. .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324800236&siteId=291194637