Quick sort (Pull the carrot method, the essence is always negative looking for the current position of a radish, a pit)

Source: Internet
Author: User

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;

Namespace QuickSort
{
Class Program
{
static void Main (string[] args)
{
list<int> list = new list<int> () {33, 19, 28, 14, 10, 67, 22, 90, 55, 100, 120, 140, 1, 12};
int low = 0;
int high = list. Count-1;
int mid = (low + high)/2;
Quicksortarr (List,low,high);
Console.readkey ();
}
public static void Quicksortarr (list<int> list,int low,int High)
{
Used to end a recursive call
if (Low >= high)
{
Return

}
int start = low;
int end = high;

int mid = (low + high)/2;

int findnum = List[mid];
Tag=0 is the possible location where the tag is initialized to indicate the number to be positioned
int tag = 0;
Tag = mid;
while (Low{
while (Low < high)
{
if (FindNum > List[high])
{
The possible position of the number to be looked for is changing every time, whether it is looking for a small one behind or looking for a large tag=high (positioning possible position, Tag=high is in the update possible location)
List[tag] = List[high];
tag = high;
Break
}
Else
{
high--;
}

}
while (Low < high)
{
if (FindNum < List[low])
{
The possible position of the number to be looked for is changing every time, whether it is looking for a small one behind or looking for a large tag=low (positioning possible position, Tag=low is in the update possible location)
List[tag] = List[low];
tag = low;
Break
}
Else
{
low++;
}
}

}
Low==high when the previous is more than the search for the number of small, behind is looking for the number of large, said that the Low==high subscript is the final number of subscript
List[low] =findnum;

Quicksortarr (list, start,low-1);
Quicksortarr (list, low+1, end);


}
}
}

Quick sort (Pull the carrot method, the essence is always negative looking for the current position of a radish, a pit)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.