Jane Xie

Wednesday, November 26, 2014

Selection Sort

void selection_sort(int *a, int len)
{
    register int i, j, min, t;
    for(i = 0; i < len - 1; i ++)
    {
        min = i;//最小值下标
        //查找最小值
        for(j = i + 1; j < len; j ++)
            if(a[min] > a[j])
                min = j;
        //交换
        if(min != i)
        {
            t = a[min];
            a[min] = a[i];
            a[i] = t;
        }
    }
}
Posted by Unknown at 1:36 AM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ►  2016 (45)
    • ►  August (1)
    • ►  July (12)
    • ►  June (9)
    • ►  May (16)
    • ►  April (7)
  • ►  2015 (53)
    • ►  December (9)
    • ►  November (2)
    • ►  October (4)
    • ►  August (3)
    • ►  July (19)
    • ►  March (3)
    • ►  February (7)
    • ►  January (6)
  • ▼  2014 (110)
    • ►  December (1)
    • ▼  November (12)
      • BT level order traversal -- Java
      • 2sum + 3sum + 4sum (hashmap solution) -- Java
      • Selection Sort
      • Evaluate Reverse Polish Notation -- Leetcode
      • Sqrt(x) -- Leetcode
      • Reverse Words in a String -- Leetcode
      • vector implementation using array -- Java
      • Sudoku Solver
      • LRU Cache -- Java
      • Encoding and decoding string
      • Print Matrix Diagonally
      • DP -- Minimal coins problem
    • ►  October (10)
    • ►  September (5)
    • ►  July (24)
    • ►  June (18)
    • ►  May (5)
    • ►  April (11)
    • ►  March (18)
    • ►  February (6)
  • ►  2013 (1)
    • ►  February (1)

About Me

Unknown
View my complete profile
Simple theme. Theme images by gaffera. Powered by Blogger.