重要算法代码

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

原文地址:https://www.cnblogs.com/ahuangliang/p/3581384.html