Profile cover photo
Profile photo
Maxim Sh
97 followers
97 followers
About
Communities and Collections
View all
Posts

Public
#Quicksort implementation. #Algorithms #CSharp #DotNet

class Program
{
static void Main(string[] args)
{
var list = new int[] { 54, 26, 93, 17, 77, 31, 44, 55, 20 };

var program = new Program();
Console.WriteLine(string.Join(",", list.Select(x => x.ToString())));
program.Quicksort(list, 0, list.Length - 1);

Console.WriteLine(string.Join(",", list.Select(x => x.ToString())));
Console.ReadLine();
}


private void Quicksort(int[] list, int low, int high)
{
if (high < low) return;

var partition = Partition(list, low, high);

Quicksort(list, low, partition - 1); //sort left part
Quicksort(list, partition + 1, high); //right part
}

private int Partition(int[] list, int low, int high)
{
var pivot = list[high];
int left = low;
int right = high - 1;
bool isPartitioned = false;

while (true)
{
while (left <= right && list[left] <= pivot)
{
left++;
}

while (right >= left && list[right] >= pivot)
{
right-;
}

if (right < left)
break;

if (list[left] > list[right])
{
swap(list, left, right);
left++;
right-;
}
}

if(list[left] > pivot)
{
swap(list, left, high);
}

return left;

}

private void swap(int[] list, int left, int right)
{
var temp = list[left];
list[left] = list[right];
list[right] = temp;
}

}
Add a comment...

Post has attachment
Such a lovely person this Min. of Finance. Caught and fined for not disclosing offshore company in France to the ethic commissioner, but had courage to stand up and tell that the fact is a fabrication. I'll try the same approach at work at see what happens. If our first figures can do that shouldn't the rest of us follow their leadership? #Canada #Liberals #politics #hypocrisy #Morneau #leadership
Add a comment...

Post has attachment
I was very surprised to find out myself that #PayPal is #stealing #money from my account in a very blatant way. They make a money #double #conversion on my behalf on attempt to #withdraw money. In the end money withdraw operation bounced back with 5% of the sum vanished. Questions to support why it is happening left unanswered. Actually the answer was "This is the way it works" Here is the article that partially explains how the scam is happening. http://www.petersandeen.com/paypal-is-stealing/

If you use #PayPal for purchases I think it's fine, though don't link a card with a significant amount on it, they can steal. Their #money #transfer service is a total scam, #WesternUnion would be cheaper.
Add a comment...

Post has shared content
Next what Trump's strategist would do accounting his Leninist grounds, probably create a red terror for Americans.
“I'm a Leninist,” Bannon proudly proclaimed. “Lenin,” he answered, “wanted to destroy the state, and that's my goal too. ... Bannon was employing Lenin's strategy for Tea Party populist goals. He included in that group the Republican and Democratic Parties, as well as the traditional conservative press.


Bannon Is Given Security Role Usually Held for Generals - The New York Times
Add a comment...

Post has attachment

Post has attachment
Interesting to watch on a mobile device. #360VR
Add a comment...

Post has attachment
I'm hooked to this car. Looking forward to have a better feel of it and maybe race. #canada #racing #radical As always great job guys at #karmacomastudio.
Add a comment...

Post has shared content
Add a comment...

Post has shared content
One of the world’s largest statues of a mosquito is in Komarno, Manitoba, Canada. It is one of several places that claim to be "The Mosquito Capital." Others are Siberia and Yellowknife, Northwest Territories, Canada. "Komar" is Ukrainian for mosquito. [This part of Canada was settled in 19th c. by many Ukrainians.] Sculpted of steel in 1984, it has a wingspan of 15 feet. It’s also a weathervane, swiveling in the wind.
Photo
Add a comment...

Post has attachment
Quite old, less but still applicable.
Add a comment...
Wait while more posts are being loaded