Guest User

Untitled

a guest
Sep 16th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1.  
  2. //InputSequence contains only unique numbers
  3. //each sequence has two entries in seq: (left boundary => right boundary) + (right boundary => left boundary)
  4.  
  5. Dictionary<int, int> seq = new Dictionary<int, int>()
  6. foreach(int n in InputSequence)
  7. {
  8.     seq[n] = n;
  9.     var lb = n,rb = n;
  10.     if (seq.contains(n - 1))
  11.     {
  12.         lb = seq[n - 1]
  13.         seq.remove(n - 1)
  14.         seq[lb] = rb;
  15.         seq[rb] = lb;
  16.     }
  17.     if (seq.contains(n + 1))
  18.     {
  19.         rb = seq[n + 1];
  20.         seq.remove(n + 1);
  21.         seq[lb] = rb;
  22.         seq[rb] = lb;
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment