马牛不是人

学姐说:“学习学习不后退”

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
//insort function
//插入法排序
//n是元素个数
template < class Elem >
void insort ( Elem A[], int n )
{
    
for ( int i = 1; i < n ; i++ )
        
for ( int j = i ; ( j > 0&& (  A[j] < A[j-1]  );j--)
            swap(A[j],A[j
-1]);
}


//选择排序
//n为元素个数
template <class Elem>
void selsort (Elem A[],int n)
{

    
forint i = 0 ; i < n ; i++ )
    {
        
int minIndex = i;
        
for ( int j = i ; j < n ; j++)
        {
            
if ( A[minIndex] > A[j] ) minIndex = j;
        }
        swap(A[minIndex],A[i]);
    }
}
posted on 2006-04-23 12:10  马牛  阅读(281)  评论(0编辑  收藏  举报