Guest

Untitled

By: a guest on Feb 12th, 2012  |  syntax: None  |  size: 0.33 KB  |  hits: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. void insertInOrder(int[] a, int n, int newValue)
  2.     {
  3.         // Shift values to the right by one until you find the
  4.         // place to insert:
  5.  
  6.         int k = n; // Start at the end
  7.         while (k > 0 && a[k-1] > newValue)
  8.         {
  9.             a[k] = a[k-1];
  10.             k--;
  11.         }
  12.         a[k] = newValue;
  13.     }