I haven't written a blog for a long time. Today I have learned to arrange for myself. I think I only know my thoughts and have never really written them. I found an ACM trainer Hdu1106, mainly because ACM has data to help you know if you are right.
Although I have been writing for a long time, I still have a sense of accomplishment. I did not read a book or anything. I only wrote it in the way I thought about the guiding ideology. I prefer this Coding method. Okay, let's talk about food.
/**
@ R: array to be sorted
@ S: the starting point of the row, starting from 0.
@ E: the end of the row, starting from n-1.
*/
Void quicksort (int r [1001], int s, int e)
{
Int t = r [s]; // Sentinel, starting
Int f = s + 1;
Int B = e; // f is the forward pointer, starting from s + 1, B is the reverse pointer, starting from e
Int m = 0;
If (s> = e) return; // exit condition
While (f <= B)
{
While (f <= B & r [f] <= t) f ++; // search for elements larger than the Sentinel
While (f <= B & r [B]> = t) B --; // find elements smaller than the sentry
// Exchange the two elements
If (f <B ){
M = r [f];
R [f] = r [B];
R [B] = m;
F ++; B --;
}
}
// Exchange sentinel and r [B], r [B] Must be smaller than Sentinel
R [s] = r [B];
R [B] = t;
// Arranged on both sides
Quicksort (r, s, B-1 );
Quicksort (r, B + 1, e );
}
Note that duplicate keys exist. For example, the data to be sorted is. This bug has been tuned for a long time.
When writing, it is best to draw images on paper and combine debugging (I am a little too dependent on debugging, so it takes time). Best practices ~~
Author: "Qinghe"