public void AddFive(int value)
        {
            Node         node5 = new Node();
            SinglyLinked sll   = new SinglyLinked(node5);

            Assert.Equal(5, sll.AddAtEnd(value));
        }
        public void AddFour(int value)
        {
            Node         node4 = new Node();
            SinglyLinked sll   = new SinglyLinked(node4);

            Assert.Equal(4, sll.AddAtEnd(value));
        }
        public void AddThree(int value)
        {
            Node         node2 = new Node();
            SinglyLinked sll   = new SinglyLinked(node2);

            Assert.Equal(3, sll.AddAtEnd(value));
        }
        public void AddAtEndTest3(int value)
        {
            Node         node1 = new Node();
            SinglyLinked sll   = new SinglyLinked(node1); // If this is set later than node1, list starts

            Assert.Equal(4, sll.AddAtEnd(value));
        }
示例#5
0
        public void FromArray_should_create_LinkedList_from_array()
        {
            // arrange
            var array = new[] { 1, 2, 3 };
            // act
            var list = SinglyLinked <int> .FromArray(array, 0, array.Length);

            // assert
            AreEqual(list, array).ShouldBeTrue();
        }
示例#6
0
 public Task StoreAsync(SinglyLinked <IEvent> events)
 {
     Events = events;
     return(Task.CompletedTask);
 }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // Declare the nodes
            Node anode1 = new Node();
            Node anode2 = new Node();
            Node anode3 = new Node();

            Node bnode1 = new Node();
            Node bnode2 = new Node();
            Node bnode3 = new Node();
            Node bnode4 = new Node();
            Node bnode5 = new Node();

            // Link the nodes
            anode1.Next = anode2;
            anode2.Next = anode3;
            anode3.Next = null;

            bnode1.Next = bnode2;
            bnode2.Next = bnode3;
            bnode3.Next = bnode4;
            bnode4.Next = bnode5;
            bnode5.Next = bnode2; // Circular list

            // Populate the nodes
            anode1.Value = 1;
            anode2.Value = 3;
            anode3.Value = 2;

            bnode1.Value = 1;
            bnode2.Value = 7;
            bnode3.Value = 2;
            bnode4.Value = 3;
            bnode5.Value = 5;

            // Instantiate the lists
            SinglyLinked asll = new SinglyLinked(anode1);
            SinglyLinked bsll = new SinglyLinked(bnode1);


            Console.WriteLine("List A:");
            asll.PrintAllNodes(); // traverses the node, prints them all out

            Console.WriteLine("List B:");
            Console.WriteLine("Infinite loop!");
            //bsll.PrintAllNodes(); // Infinite loop!

            Console.WriteLine();

            Console.WriteLine($"List A is a loop? {asll.hasLoop()}");
            Console.WriteLine($"List B is a loop? {bsll.hasLoop()}");

            //sll.Find(3); // Traverses the node, prints out the parameter if found

            //int dummy = sll.AddAtEnd(11); // Adds new node and value to the end of the list.

            //dummy = sll.Add(1); // Adds new node and value to the start of the list.

            //Console.WriteLine("Here's the list again");
            //sll.PrintAllNodes(); // prints the list again to show it worked.
            //Console.ReadLine();
        }
示例#8
0
 private static bool AreEqual(SinglyLinked <int> list, int[] array, int position = 0) =>
 list.Head == array[position] && (list.IsLast || AreEqual(list.Tail, array, ++position));
示例#9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="chr"></param>
 /// <returns></returns>
 public static ExpressionResult Fail(SinglyLinked <char> chr) =>
 new ExpressionResult(false, chr, chr);
示例#10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="start"></param>
 /// <param name="end"></param>
 /// <returns></returns>
 public static ExpressionResult Success(SinglyLinked <char> start, SinglyLinked <char> end) =>
 new ExpressionResult(true, start, end);
示例#11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="isMatch"></param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 public ExpressionResult(bool isMatch, SinglyLinked <char> start, SinglyLinked <char> end)
 {
     IsMatch = isMatch;
     Start   = start;
     End     = end;
 }
示例#12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="isMatch"></param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 public void Deconstruct(out bool isMatch, out SinglyLinked <char> start, out SinglyLinked <char> end)
 {
     isMatch = IsMatch;
     start   = Start;
     end     = End;
 }
示例#13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="event"></param>
 /// <returns></returns>
 protected virtual Document PushEvent <TEvent>(TEvent @event) where TEvent : IEvent
 {
     Events.Emit(@event);
     History = History.Push(@event);
     return(this);
 }