重要算法代码

时间:2014-03-05 17:51:02   收藏:0   阅读:530

Binary-Search (A, x)

  l = 0, r = A.length

  while l < r :

    i = l + (r - l) / 2

    if x < A[i]: r = i

    else if x > A[i]: l = i + 1

    else return i

  return -1 // Not-Found

 

Insert-Sort (A) 

  for i = 1 to A.length

    test = A[i]

    j = i - 1

    while j >= 0 and test < A[j]: //Ascend

      A[j+1] = A[j]

    A[j+1] = test

 

DFS(solutioin)

  if solution is ok: process(solution)

  foreach all candidates

    DFS(solution + candidate)

    if finished: return

重要算法代码,布布扣,bubuko.com

原文:http://www.cnblogs.com/ahuangliang/p/3581384.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!