Saturday, 23 April 2011

C/C++ : Quick Sort

Here is the source code of quick sort. This algorithm also knowns as most efficient search algorithm.
I don't know why but it doesn't work appropriately. It works on 100 data but more than that it crushes.
If you find bug let me know, thank you.

I've used Hoare-partition
Here is the code.

int partition( int a[ ]int low, int high )
{
    int piwot, right, left;
    left = low + 1 ;
    right = high ;
    piwot = alow ];
    while(1)
    {
        while( aright ] > piwot ) right--;
        while( a[ left ] < piwot &&a left < high ) left++;
        if ( left < right )
            swap( a, left, right );
        else{
            swap( a, low, right );
            return right;
        }
    }
}

void quickSort( int a[ ]int low, int high)
{
    int part;
    if( low &lt; high )
    {
        part = partition( a, low, high );
        quickSort( a, low, part -1 );
        quickSort( a, part +1, high );
    }
}

Tuesday, 19 April 2011

C# : Detecting cursor position in RichTextBox

When i was working on RichTextBox the main thing that i had to handle was counting lines and detecting cursor position. Now lets see how to get these things done. Let me tell you about how to detect cursor position.

You need to use:
RichTextBox.SelectionStart and RichTextBox.GetLineFromCharIndex()
But make sure you use instance method of RichTextBox class as show
here :GetLineFromCharIndex[^] and GetLineFromCharIndex[^]
    
private static int EM_LINEINDEX = 0xbb;

int index, line, col;

[DllImport("user32.dll")]

extern static int SendMessage(IntPtr hwnd, int message, int wparam, int lparam);   


[DllImport("user32.dll")]
This line of code shouldn't be written in any method or functions.
You will find detailed explanation here:
 DllImportAttribute[^]

Monday, 18 April 2011

"Love" from Chicken Soup for the Soul

Love: The One Creative Force
Spread love everywhere you go: first of all in your own house. Give love to your children, to your wife or husband, to a next door neighbor. . . . Let no one ever come to you without leaving better and happier. Be the living expression of God's kindness; kindness in your face, kindness in your eyes, kindness in your smile, kindness in your warm greeting.
Mother Teresa

A college professor had his sociology class go into the Baltimore slums to get case histories of 200 young boys. They were asked to write an evaluation of each boy's future. In every case the students wrote, "He hasn't got a chance." Twenty-five years later another sociology professor came across the earlier study. He had his students follow up on the project to see what had happened to these boys. With the exception of 20 boys who had moved away or died, the students learned that 176 of the remaining 180 had achieved more than ordinary success as lawyers, doctors and businessmen.
The professor was astounded and decided to pursue the matter further. Fortunately, all the men were in the area and he was able to ask each one, "How do you account for your success?" In each case the reply came with feeling, 'There was a teacher."
The teacher was still alive, so he sought her out and asked the old but still alert lady what magic formula she had used to pull these boys out of the slums into successful achievement.
The teacher's eyes sparkled and her lips broke into a gentle smile. "It's really very simple," she said. "I loved those boys."
Eric Butterworth