Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //InputSequence contains only unique numbers
- //each sequence has two entries in seq: (left boundary => right boundary) + (right boundary => left boundary)
- Dictionary<int, int> seq = new Dictionary<int, int>()
- foreach(int n in InputSequence)
- {
- seq[n] = n;
- var lb = n,rb = n;
- if (seq.contains(n - 1))
- {
- lb = seq[n - 1]
- seq.remove(n - 1)
- seq[lb] = rb;
- seq[rb] = lb;
- }
- if (seq.contains(n + 1))
- {
- rb = seq[n + 1];
- seq.remove(n + 1);
- seq[lb] = rb;
- seq[rb] = lb;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment