Write the algorithm of the quick sort, Data Structure & Algorithms

Ans.

An algorithm for the quick sort is as follows:

void quicksort ( int a[ ], int lower, int upper )

{

int i ;

if ( upper > lower ) {

i = split ( a, lower, upper ) ; quicksort ( a, lower, i - 1 ) ; quicksort ( a, i + 1, upper ) ;                                }

}

int split ( int a[ ], int lower, int upper ){

int i, p, q, t ;

p = lower + 1 ;

q = upper ;

i = a[lower] ;

while ( q >= p )

{

while ( a[p] < i )

p++ ;

while ( a[q] > i )

q-- ;

if ( q > p )

{

t = a[p] ; a[p] = a[q] ; a[q] = t ;

}

}

t = a[lower] ; a[lower] = a[q] ; a[q] = t ;

return q ; }

Posted Date: 7/12/2012 8:33:20 AM | Location : United States







Related Discussions:- Write the algorithm of the quick sort, Assignment Help, Ask Question on Write the algorithm of the quick sort, Get Answer, Expert's Help, Write the algorithm of the quick sort Discussions

Write discussion on Write the algorithm of the quick sort
Your posts are moderated
Related Questions
Q. Give the algorithm for the selection sort. Describe the behaviours of selection sort when the input given is already sorted.

A list item stores pointers and an element to predecessor and successor. We call a pointer to a list item a handle . This looks simple enough, but pointers are so powerful tha

WRITE AN ALGORITHM TO READ TWO NUMBERS AND PRINT THE LOWER VALUE

How to construct a data flow diagram for a college assignment and marking systemA

A significant aspect of Abstract Data Types is that they explain the properties of a data structure without specifying the details of its implementation. The properties might be im

#questWrite an algorithm for multiplication of two sparse matrices using Linked Lists.ion..

Enumerate about the Data structure An arrangement of data in memory locations to signify values of the carrier set of an abstract data type. Realizing computational mechanis

#question. merging 4 sorted files containing 50,10,25,15 records will take time?

The complexity of multiplying two matrices of order m*n and n*p is    mnp