Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gurimusan/3b241bc7bf8e80464f55 to your computer and use it in GitHub Desktop.
Save gurimusan/3b241bc7bf8e80464f55 to your computer and use it in GitHub Desktop.

2.1-1

2.1-2

INSERT-SORT(A)
  for j=2 to A.length
    key = A[j]
    i = j-1
    while i>0 かつ A[i]<key
      A[i+1] = A[i]
      i = i-1
    A[i+1] = key

2.1-3

LINEAR-SEARCH(v, A)
  i = Nil
  for j=1 to A.length
    if v == A[j]
      i = A[k]
      break
  return i

2.1-4

CALC-BITS(A, B)
  n = A.length
  for i=1 to n+1
    C[i] = 0
  for i=1 to n
    v = A[i] + B[i] + C[i]
    C[i] = v % 2
    if v >= 2:
      C[i+1] = 1
  return C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment