Pseudocodes  of  Sorting  Algorithms

 

Insertion Sort

 

for( int p = 1; p < m; p++ )

{

   temp = a[p];

   for( int j = p; j > 0; && temp < a[j-1]; j-- )

     a[j] = a[j-1];

   a[j] = temp;

}

 

 

Quicksort

 

Quicksort( A, 0, n-1 )

{

   if( n > 1 )

      q = Partition( A, 0, n-1 )  

      Quicksort( A, 0, q );

      Quicksort( A, q+1, n-1 );

}

 

 

Partitioning for Quicksort:

 

int Partition( A, 0, n-1 )

{

   int x = A[p];

   i = 0;

   j = n-1;

   while( true )

   {

      while( x <= A[j] )

         j--;

      while( x > A[i] )

      {

         i++;

      if( i < j )

         swap( A[i], A[j] )

      else

         return j;

      }

}