using System.Collections.Generic;
public static void Main()
Console.WriteLine("Hello World");
var middle = new Node(5);
public static void PrintNodes(Node node){
Console.WriteLine(node.Value);
public class LinkedList<T> : ICollection<T>{
public LinkedListNode<T> Head {get; private set;}
public LinkedListNode<T> Tail {get; private set;}
public void AddFirst(T val){
AddFirst(new LinkedListNode<T>(val));
public void AddFirst(LinkedListNode<T> node){
if(Count == 1) Tail = Head;
public void AddLast(T val){
AddLast(new LinkedListNode<T>(val));
public void AddLast(LinkedListNode<T> node){
if(Count == 0) Head = node;
public void RemoveFirst(){
if(Count ==0)Tail = null;
public void RemoveLast(){
while(current.Next != Tail){
public int Count{get; private set; }
public bool Contains(T item){
if(current.Value.Equals(item)) return true;
public void CopyTo(T[] array, int arrayIndex){
array[arrayIndex++] = current.Value;
public bool IsReadOnly { get{return false; }}
public bool Remove(T item){
LinkedListNode<T> previous = null;
if(current.Value.Equals(item)){
previous.Next = current.Next;
if(current.Next == null){
System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerable<T>.GetEnumerator(){
yield return current.Value;
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator(){
return ((System.Collections.Generic.IEnumerable<T>)this).GetEnumerator();
public class DoublyLinkedList<T> : ICollection<T>{
public DoublyLinkedListNode<T> Head {get; private set;}
public DoublyLinkedListNode<T> Tail {get; private set;}
public void AddFirst(T val){
AddFirst(new DoublyLinkedListNode<T>(val));
public void AddFirst(DoublyLinkedListNode<T> node){
if(Count == 1) Tail = Head;
else temp.Previous = Head;
public void AddLast(T val){
AddLast(new DoublyLinkedListNode<T>(val));
public void AddLast(DoublyLinkedListNode<T> node){
if(Count == 0) Head = node;
public void RemoveFirst(){
if(Count ==0)Tail = null;
else Head.Previous = null;
public void RemoveLast(){
Tail.Previous.Next = null;
public int Count{get; private set; }
public bool Contains(T item){
if(current.Value.Equals(item)) return true;
public void CopyTo(T[] array, int arrayIndex){
array[arrayIndex++] = current.Value;
public bool IsReadOnly { get{return false; }}
public bool Remove(T item){
DoublyLinkedListNode<T> previous = null;
if(current.Value.Equals(item)){
previous.Next = current.Next;
if(current.Next == null){
current.Next.Previous = previous;
System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerable<T>.GetEnumerator(){
yield return current.Value;
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator(){
return ((System.Collections.Generic.IEnumerable<T>)this).GetEnumerator();
public class DoublyLinkedListNode<T>
public DoublyLinkedListNode(T val) {
public T Value { get; set; }
public DoublyLinkedListNode<T> Next {get; set;}
public DoublyLinkedListNode<T> Previous { get; set; }
public class LinkedListNode<T>{
public LinkedListNode(T val){
public T Value {get; set;}
public LinkedListNode<T> Next {get; set;}
public int Value{get; set;}
public Node Next {get; set; }
public Node(int val, Node next){