SHARE
TWEET

First pass at in-place interleave

a guest Feb 8th, 2011 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void deinterleave(int *a, int len)
  2. {
  3.     for (int i = 0; i < len/2; i++)
  4.     {
  5.         // move a left int into place
  6.         for (int j = i * 2; // initial position
  7.              j > i;         // final position
  8.              j --)
  9.         {
  10.             int t = a[j-1];
  11.             a[j-1] = a[j];
  12.             a[j] = t;
  13.         }
  14.     }
  15. }
  16.  
  17. void interleave(int *a, int len)
  18. {
  19.     for (int i = len/2-1; i > 0; i--)
  20.     {
  21.         // move a left int into place
  22.         for (int j = i; // initial position
  23.              j < i*2;   // final position
  24.              j ++)
  25.         {
  26.             int t = a[j+1];
  27.             a[j+1] = a[j];
  28.             a[j] = t;
  29.         }
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top