static void Main() { LinkedListClass linkedListClass = GetLinkedList(); Console.WriteLine(linkedListClass.Count); PrintLinkedList(linkedListClass); }
public void AddSimpleTest() { var linkedList = new LinkedListClass <string>(); linkedList.IsEmpty.Should().BeTrue(); linkedList.Count.Should().Be(0); linkedList.AddFirst("B"); linkedList.AddFirst("A"); linkedList.AddLast("C"); linkedList.AddLast("D"); linkedList.AddLast("E"); linkedList.IsEmpty.Should().BeFalse(); linkedList.Count.Should().Be(5); linkedList.First.Data.Should().Be("A"); linkedList.First.Next.Data.Should().Be("B"); linkedList.First.Next.Next.Data.Should().Be("C"); linkedList.First.Next.Next.Next.Data.Should().Be("D"); linkedList.First.Next.Previous.Data.Should().Be("A"); linkedList.First.Next.Next.Previous.Data.Should().Be("B"); linkedList.First.Next.Next.Next.Previous.Data.Should().Be("C"); linkedList.Last.Data.Should().Be("E"); linkedList.Last.Previous.Data.Should().Be("D"); linkedList.Clear(); linkedList.IsEmpty.Should().BeTrue(); linkedList.Count.Should().Be(0); }
private static LinkedListClass GetLinkedList() { LinkedListClass linkedListClass = new LinkedListClass(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine() .Split(' '); string command = input[0]; int number = int.Parse(input[1]); switch (command) { case "Add": linkedListClass.Add(number); break; case "Remove": linkedListClass.Remove(number); break; } } return(linkedListClass); }
private static void PrintLinkedList(LinkedListClass linkedListClass) { StringBuilder sb = new StringBuilder(); foreach (var number in linkedListClass) { sb.Append($"{number.ToString()} "); } Console.WriteLine(sb.ToString()); }
public void ReverseSimpleTest() { var linkedList = new LinkedListClass <string>(); linkedList.AddLast("A"); linkedList.AddLast("B"); linkedList.AddLast("C"); linkedList.Reverse(); linkedList.First.Data.Should().Be("C"); linkedList.Last.Data.Should().Be("A"); }
public void SearchAndFindNode() { LinkedListClass list = new LinkedListClass(); list.Add1(56); list.Add1(30); list.Add1(70); Node node = list.Search(30); Assert.AreEqual(30, node.data); }
public void InsertAtPosition() { LinkedListClass list = new LinkedListClass(); list.Add1(56); list.Add1(30); list.Add1(70); list.InsertAtParticularPosition(3, 40); int position = list.findPosition(40); Assert.AreEqual(3, 3); }
public void DeleteAndGetSize() { LinkedListClass list = new LinkedListClass(); list.Add1(56); list.Add1(30); list.Add1(40); list.Add1(70); list.DeleteNode(40); int size = list.size(); Assert.AreEqual(3, 3); }
public void WriteAndRead_LinkedList() { try { LinkedListClass s = new LinkedListClass(); s.s.AddFirst(""); IO.WriteToXmlFile(IO.CurrentDirectoryFolder + "\\tests\\WriteToXmlFileTesting.xml", s); Assert.Fail(); } catch { Assert.AreEqual(true, true); } }
public void FindSimpleTest() { var linkedList = new LinkedListClass <string>(); linkedList.AddLast("A"); linkedList.AddLast("B"); linkedList.AddLast("C"); var firstItem = linkedList.Find("A"); var secondItem = linkedList.Find("B"); var thirdItem = linkedList.Find("C"); firstItem.Data.Should().Be("A"); secondItem.Data.Should().Be("B"); thirdItem.Data.Should().Be("C"); var fourthItem = linkedList.Find("X"); fourthItem.Should().Be(null); }
public void RemoveSimpleTest() { var linkedList = new LinkedListClass <string>(); linkedList.AddLast("A"); linkedList.AddLast("B"); linkedList.AddLast("C"); linkedList.AddLast("D"); linkedList.AddLast("E"); linkedList.RemoveFirst(); linkedList.RemoveLast(); linkedList.First.Data.Should().Be("B"); linkedList.Last.Data.Should().Be("D"); linkedList.RemoveLast(); linkedList.RemoveLast(); linkedList.Count.Should().Be(1); linkedList.First.Data.Should().Be("B"); }
public void Test1() { var linkedList = new LinkedListClass <string>(); linkedList.AddLast("A"); linkedList.AddLast("B"); linkedList.AddLast("C"); linkedList.AddLast("D"); linkedList.AddLast("E"); linkedList.Contains("A").Should().BeTrue(); linkedList.Contains("B").Should().BeTrue(); linkedList.Contains("C").Should().BeTrue(); linkedList.Contains("D").Should().BeTrue(); linkedList.Contains("E").Should().BeTrue(); linkedList.Contains("F").Should().BeFalse(); linkedList.Contains("G").Should().BeFalse(); linkedList.Contains("H").Should().BeFalse(); }
public void LinkedList() { LinkedList <string> strings = new LinkedList <string>(); strings.AddLast("test1"); strings.AddLast("test2"); LinkedListClass a = new LinkedListClass { Strings = strings, }; XmlDocument target = new XmlDocument(); Serializer.Serialize((SystemXmlAdapter)target, a); Assert.AreEqual(1, target.DocumentElement.ChildNodes.Count); LinkedListClass b = Deserializer.Deserialize <LinkedListClass>((SystemXmlAdapter)target); IEnumerator <string> aEnum = a.Strings.GetEnumerator(); IEnumerator <string> bEnum = b.Strings.GetEnumerator(); while (true) { bool aDone = !aEnum.MoveNext(); bool bDone = !bEnum.MoveNext(); if (aDone && bDone) { break; } Assert.AreEqual(aDone, bDone); Assert.AreEqual(aEnum.Current, bEnum.Current); } aEnum.Dispose(); bEnum.Dispose(); }
public void LinkedList() { LinkedList <string> strings = new LinkedList <string>(); strings.AddLast("test1"); strings.AddLast("test2"); LinkedListClass a = new LinkedListClass { Strings = strings, }; JObject target = new JObject(); Serializer.Serialize((NewtonsoftJsonAdapter)target, a); AssertChildren(3, target); LinkedListClass b = Deserializer.Deserialize <LinkedListClass>((NewtonsoftJsonAdapter)target); IEnumerator <string> aEnum = a.Strings.GetEnumerator(); IEnumerator <string> bEnum = b.Strings.GetEnumerator(); while (true) { bool aDone = !aEnum.MoveNext(); bool bDone = !bEnum.MoveNext(); if (aDone && bDone) { break; } Assert.AreEqual(aDone, bDone); Assert.AreEqual(aEnum.Current, bEnum.Current); } aEnum.Dispose(); bEnum.Dispose(); }