<commit_before>﻿using System;

namespace Algorithm.Sandbox.DataStructures
{
    //define the generic node
    public class AsDoublyLinkedListNode<T>
    {
        public AsDoublyLinkedListNode<T> Previous;
        public AsDoublyLinkedListNode<T> Next;
        public T Data;

        public AsDoublyLinkedListNode(T data)
        {
            this.Data = data;
        }
    }

    /// <summary>
    /// A singly linked list implementation
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class AsDoublyLinkedList<T>
    {
        public AsDoublyLinkedListNode<T> Head;
        public AsDoublyLinkedListNode<T> Tail;
        //marks this data as the new head
        //cost O(1)
        public void InsertFirst(T data)
        {
            var newNode = new AsDoublyLinkedListNode<T>(data);

            if (Head != null)
            {
                Head.Previous = newNode;
            }

            newNode.Next = Head;

            Head = newNode;

            if (Tail == null)
            {
                Tail = Head;
            }

        }

        //insert at the end
        //costs O(1)
        public void InsertLast(T data)
        {
            var newNode = new AsDoublyLinkedListNode<T>(data);

            if (Tail == null)
            {
                InsertFirst(data);
                return;
            }

            Tail.Next = newNode;
            newNode.Previous = Tail;

            Tail = newNode;

        }

        //cost O(1)
        public T DeleteFirst()
        {
            if (Head == null)
            {
                throw new Exception("Empty list");
            }

            var firstData = Head.Data;

            if (Head == Tail)
            {
                Head = null;
                Tail = null;
            }
            else
            {
                Head.Next.Previous = null;
                Head = Head.Next;
            }

            return firstData;
        }

        //cost O(1)
        public T DeleteLast()
        {
            if (Tail == null)
            {
                throw new Exception("Empty list");
            }

            var lastData = Tail.Data;

            if (Tail == Head)
            {
                Head = null;
                Tail = null;
            }
            else
            {
                Tail.Previous.Next = null;
                Tail = Tail.Previous;
            }

            return lastData;
        }<commit_msg>rename<commit_after>﻿using System;

namespace Algorithm.Sandbox.DataStructures
{
    //define the generic node
    public class AsDoublyLinkedListNode<T>
    {
        public AsDoublyLinkedListNode<T> Previous;
        public AsDoublyLinkedListNode<T> Next;
        public T Data;

        public AsDoublyLinkedListNode(T data)
        {
            this.Data = data;
        }
    }

    /// <summary>
    /// A singly linked list implementation
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class AsDoublyLinkedList<T>
    {
        public AsDoublyLinkedListNode<T> Head;
        public AsDoublyLinkedListNode<T> Tail;
        //marks this data as the new head
        //cost O(1)
        public void InsertFirst(T data)
        {
            var newNode = new AsDoublyLinkedListNode<T>(data);

            if (Head != null)
            {
                Head.Previous = newNode;
            }

            newNode.Next = Head;

            Head = newNode;

            if (Tail == null)
            {
                Tail = Head;
            }

        }

        //insert at the end
        //costs O(1)
        public void InsertLast(T data)
        {
            var newNode = new AsDoublyLinkedListNode<T>(data);

            if (Tail == null)
            {
                InsertFirst(data);
                return;
            }

            Tail.Next = newNode;
            newNode.Previous = Tail;

            Tail = newNode;

        }

        //cost O(1)
        public T DeleteFirst()
        {
            if (Head == null)
            {
                throw new Exception("Empty list");
            }

            var headData = Head.Data;

            if (Head == Tail)
            {
                Head = null;
                Tail = null;
            }
            else
            {
                Head.Next.Previous = null;
                Head = Head.Next;
            }

            return headData;
        }

        //cost O(1)
        public T DeleteLast()
        {
            if (Tail == null)
            {
                throw new Exception("Empty list");
            }

            var tailData = Tail.Data;

            if (Tail == Head)
            {
                Head = null;
                Tail = null;
            }
            else
            {
                Tail.Previous.Next = null;
                Tail = Tail.Previous;
            }

            return tailData;
        }
{'fraction_non_alphanumeric': 0.08867195444376652, 'fraction_numerical': 0.0016270083384177345, 'mean_word_length': 1.0098079280751941, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '822728', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1302, 'n_words': 314}