From 3554513540ddf8d7719307e8afe218ff982e4e34 Mon Sep 17 00:00:00 2001 From: alrudenko Date: Thu, 15 Dec 2016 18:05:04 +0200 Subject: [PATCH 1/9] Create ListNode.cs --- CSharp/Single/ListNode.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 CSharp/Single/ListNode.cs diff --git a/CSharp/Single/ListNode.cs b/CSharp/Single/ListNode.cs new file mode 100644 index 0000000..6146300 --- /dev/null +++ b/CSharp/Single/ListNode.cs @@ -0,0 +1,16 @@ +public class ListNode + { + public T Value { get; set; } + public ListNode Next { get; set; } + + public ListNode(T value) + { + Value = value; + } + + public ListNode(T value, ListNode next) + { + Value = value; + Next = next; + } + } From 0b5d4cc515242b9ab4c90284be33be69954f8bfb Mon Sep 17 00:00:00 2001 From: alrudenko Date: Thu, 15 Dec 2016 18:06:40 +0200 Subject: [PATCH 2/9] Create Program.cs --- CSharp/Single/Program.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 CSharp/Single/Program.cs diff --git a/CSharp/Single/Program.cs b/CSharp/Single/Program.cs new file mode 100644 index 0000000..86a8511 --- /dev/null +++ b/CSharp/Single/Program.cs @@ -0,0 +1,16 @@ +class Program + { + static void Main(string[] args) + { + ListNode first = new ListNode(1); + ListNode second = new ListNode(2); + first.Next = second; + ListNode zero = new ListNode(0, first); + + Console.WriteLine(zero.Value); + Console.WriteLine(zero.Next.Value); + Console.WriteLine(zero.Next.Next.Value); + + Console.ReadKey(); + } + } From d0316ed6d8312b71429f90035ab15b6790a3a990 Mon Sep 17 00:00:00 2001 From: alrudenko Date: Thu, 15 Dec 2016 18:07:30 +0200 Subject: [PATCH 3/9] Create ListNode.cs --- CSharp/Double/ListNode.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 CSharp/Double/ListNode.cs diff --git a/CSharp/Double/ListNode.cs b/CSharp/Double/ListNode.cs new file mode 100644 index 0000000..53215db --- /dev/null +++ b/CSharp/Double/ListNode.cs @@ -0,0 +1,11 @@ +public class ListNode + { + public T Value { get; set; } + public ListNode Previous { get; internal set; } + public ListNode Next { get; internal set; } + + public ListNode(T value) + { + Value = value; + } + } From d037f89213fd33b4725f3b8f1a21458b46b70cd9 Mon Sep 17 00:00:00 2001 From: alrudenko Date: Thu, 15 Dec 2016 18:08:58 +0200 Subject: [PATCH 4/9] Create DLL.cs --- CSharp/Double/DLL.cs | 97 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 CSharp/Double/DLL.cs diff --git a/CSharp/Double/DLL.cs b/CSharp/Double/DLL.cs new file mode 100644 index 0000000..9947f5a --- /dev/null +++ b/CSharp/Double/DLL.cs @@ -0,0 +1,97 @@ +public class DLL : System.Collections.Generic.IEnumerable + { + private ListNode _head; + private ListNode _tail; + + public int Count { get; private set; } + /// + /// Adding new node to tail of list + /// + /// Value for new node + public void Add(T value) + { + ListNode _tmpNode = new ListNode(value); + if (_head == null) + { + _head = _tmpNode; + _tail = _tmpNode; + } + else + { + _tail.Next = _tmpNode; + _tail.Next.Previous = _tail; + _tail = _tmpNode; + } + Count++; + } + + /// + /// Make your list clear + /// + public void Clear() + { + _head = null; + _tail = null; + Count = 0; + } + + /// + /// Removing node by value from list + /// + /// Value of node + /// + public bool Remove(T value) + { + ListNode previous = null; + ListNode current = _head; + + while (current != null) + { + if (current.Value.Equals(value)) + { + + if (previous != null) + { + previous.Next = current.Next; + current.Next.Previous = current.Previous; + + if (current.Next == null) + { + _tail = previous; + } + } + else + { + _head = _head.Next; + + if (_head == null) + { + _tail = null; + } + } + + Count--; + return true; + } + previous = current; + current = current.Next; + } + return false; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)this).GetEnumerator(); + } + + public IEnumerator GetEnumerator() + { + ListNode current = _head; + + while (current != null) + { + yield return current.Value; + current = current.Next; + } + } + } From 89aef79e5a3d5a85027921086f454839d6249efa Mon Sep 17 00:00:00 2001 From: alrudenko Date: Thu, 15 Dec 2016 18:09:49 +0200 Subject: [PATCH 5/9] Create Program.cs --- CSharp/Double/Program.cs | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 CSharp/Double/Program.cs diff --git a/CSharp/Double/Program.cs b/CSharp/Double/Program.cs new file mode 100644 index 0000000..473b735 --- /dev/null +++ b/CSharp/Double/Program.cs @@ -0,0 +1,46 @@ +class Program + { + static void Main(string[] args) + { + DLL instance = new DLL { }; + + #region Adding items + + instance.Add(12); + instance.Add(15); + instance.Add(20); + instance.Add(25); + + Display(instance, "List"); + + #endregion + + #region Removing item + + instance.Remove(20); + + Display(instance, "20 was removed"); + + #endregion + + #region Clearing list + + instance.Clear(); + Display(instance, "List is cleared"); + + #endregion + + Console.ReadKey(); + } + + public static void Display(DLL words, string test) + { + Console.WriteLine(test); + foreach (int word in words) + { + Console.Write(word + " "); + } + Console.WriteLine(); + Console.WriteLine(); + } + } From a22ff74b20e1cd84e2508994f8bd2a5e6b648811 Mon Sep 17 00:00:00 2001 From: alrudenko Date: Thu, 15 Dec 2016 18:14:06 +0200 Subject: [PATCH 6/9] Added C# example for double linked list --- CSharp/Double/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CSharp/Double/Program.cs b/CSharp/Double/Program.cs index 473b735..04a5ceb 100644 --- a/CSharp/Double/Program.cs +++ b/CSharp/Double/Program.cs @@ -43,4 +43,4 @@ public static void Display(DLL words, string test) Console.WriteLine(); Console.WriteLine(); } - } + } From a8da8839821299c68997d811a1100ac23cd821e4 Mon Sep 17 00:00:00 2001 From: alrudenko Date: Thu, 15 Dec 2016 18:14:26 +0200 Subject: [PATCH 7/9] Added C# example for double linked list From 919344f405827b7cdea9980b8dfd06a75c57936f Mon Sep 17 00:00:00 2001 From: alrudenko Date: Thu, 15 Dec 2016 18:14:49 +0200 Subject: [PATCH 8/9] Added C# example for double linked list From 87aad36a717ac6335d69e566c7be89c17649d612 Mon Sep 17 00:00:00 2001 From: alrudenko Date: Thu, 15 Dec 2016 18:15:21 +0200 Subject: [PATCH 9/9] Added C# example for single linked list --- CSharp/Single/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/CSharp/Single/Program.cs b/CSharp/Single/Program.cs index 86a8511..ba55abc 100644 --- a/CSharp/Single/Program.cs +++ b/CSharp/Single/Program.cs @@ -14,3 +14,4 @@ static void Main(string[] args) Console.ReadKey(); } } +