Exemplo n.º 1
0
        public void Main()
        {
            var list = new HashedLinkedList <int> {
                2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59
            };

            // View of item
            list.ViewOf(2);

            // Last view of item
            list.LastViewOf(11);

            // View in range
            var view = list.View(0, 3);

            // Slide with offset
            view.Slide(3);

            // Slide with offset and set lenght
            view.Slide(-3, 3);

            // Try slide with offset and set lenght
            var hasSucceed = view.TrySlide(-10, 3);

            // Try slide with offset and set lenght
            view.TrySlide(3, -3);

            var view2 = list.View(0, 3);
            var view3 = list.View(1, 3);

            // Check if views overlap
            Overlap(view2, view3);

            // Check if views contained in each other
            ContainsView(view2, view3);

            // Span views
            var spannedView = view2.Span(view3);

            // Invalidate all views by shuffle
            list.Shuffle();

            // Check if view is valid
            Console.WriteLine($"View is valid? {view.IsValid}");
        }
Exemplo n.º 2
0
        public void Main()
        {
            // Construct hashed array list using collection initializer
            var list = new HashedLinkedList <int> {
                2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59
            };

            // Chose from list
            list.Choose();

            var array = new int[list.Count];

            // Copy list to array
            list.CopyTo(array, 0);

            // Add item to the end of list
            list.Add(61);

            // Add range to list
            array = new[] { 67, 71, 73, 79, 83 };
            list.AddRange(array);

            // Check if list contains an item
            list.Contains(list.Choose());

            // Check if list contains all items in enumerable
            list.ContainsRange(array);

            // Count all occuerence of an item
            list.CountDuplicates(list.Choose());

            // Find an item in list
            var itemToFind = list.Last;

            list.Find(ref itemToFind);

            // Return all occurence of an item
            list.FindDuplicates(itemToFind);

            // Remove within range
            list.RemoveIndexRange(0, 3);

            var range = new[] { list.First, list.Last };

            // Remove all items in enumerable from list
            list.RemoveRange(range);

            // Retain all items in enumarable from list
            list.RetainRange(list.ToArray());

            var lastItem = list.Last;

            // Find last index of an item
            list.LastIndexOf(lastItem);

            // Insert at the end of list
            list.InsertLast(100);

            // Insert at the beginning of list
            list.InsertFirst(-100);

            // Reverse list
            list.Reverse();

            // Shuffle list
            list.Shuffle();

            // Sort list
            list.Sort();

            // Check if list is sorted
            var isSorted = list.IsSorted();

            // Print all items in list by indexer
            var index = 0;

            foreach (var item in list)
            {
                Console.WriteLine($"list[{index++}] = {item}");
            }

            // Clear list
            list.Clear();
        }