Code:
public static class CircularLinkedList { public static LinkedListNode<T> NextOrFirst<T>(this LinkedListNode<T> current) { return current.Next ?? current.List.First; } public static LinkedListNode<T> PreviousOrLast<T>(this LinkedListNode<T> current) { return current.Previous ?? current.List.Last; } public static LinkedListNode<T> Rewind<T>(this LinkedListNode<T> current, int num) { while (num != 0) { current = num > 0 ? current.NextOrFirst() : current.PreviousOrLast(); num -= Math.Sign(num); } return current; } }
No comments:
Post a Comment