Added Doubly Linked List Node

This commit is contained in:
Luke Else 2022-03-06 09:10:17 +00:00
parent fffce6c6bb
commit 80bb1cc492
3 changed files with 31 additions and 5 deletions

View File

@ -5,9 +5,9 @@ using System.Threading.Tasks;
namespace C_.Datastructures.Nodes namespace C_.Datastructures.Nodes
{ {
public interface ILinkedListNode<T> public interface INode<T>
{ {
public T? Value { get; set; } public T? Value { get; set; }
public ILinkedListNode<T>? Next { get; set; } public INode<T>? Next { get; set; }
} }
} }

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C_.Datastructures.Nodes.LinkedList
{
internal class DoublyLinkedListNode<T> : INode<T>
{
public T? Value { get; set; } = default;
public INode<T>? Next { get; set; } = default(DoublyLinkedListNode<T>);
public INode<T>? Prev { get; set; } = default(DoublyLinkedListNode<T>);
public static DoublyLinkedListNode<T> Create(T? value, DoublyLinkedListNode<T>? next, DoublyLinkedListNode<T> prev)
{
return new DoublyLinkedListNode<T>
{
Value = value,
Next = next,
Prev = prev
};
}
}
}

View File

@ -4,12 +4,12 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace C_.Datastructures.Nodes namespace C_.Datastructures.Nodes.LinkedList
{ {
internal class LinkedListNode<T> : ILinkedListNode<T> internal class LinkedListNode<T> : INode<T>
{ {
public T? Value { get; set; } = default; public T? Value { get; set; } = default;
public ILinkedListNode<T>? Next { get; set; } = default(LinkedListNode<T>); public INode<T>? Next { get; set; } = default(LinkedListNode<T>);
public static LinkedListNode<T> Create(T? value, LinkedListNode<T>? next) public static LinkedListNode<T> Create(T? value, LinkedListNode<T>? next)
{ {