<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace Basics.Structures
{
    public class StackOnList<T> : IStack<T>
    {
        private class Node<X>
        {
            public X Value { get; set; }
            public Node<X> Next { get; set; }
        }

        private int _size = 0;
        private Node<T> _head = null;

        /// <summary>
        /// Pushes value to the stack.
        /// </summary>
        public void Push(T value)
        {
            _size++;
            _head = new Node<T>
            {
                Value = value,
                Next = _head
            };
        }

        /// <summary>
        /// Pops value out of the stack.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown when stack is empty.</exception>
        public T Pop()
        {
            if (_head == null)
                throw new InvalidOperationException("Stack is empty.");

            _size--;
            var current = _head;
            _head = _head.Next;
            return current.Value;
        }

        /// <summary>
        /// Checks whether stack is empty.
        /// </summary>
        public bool IsEmpty
        {
            get { return _head == null; }
        }

        /// <summary>
        /// Returns size of the stack.
        /// </summary>
        public int Size
        {
            get { return _size; }
        }

        #region IEnumerable Members

        public IEnumerator<T> GetEnumerator()
        {
            return new LinkedListEnumerator<T>(_head);
            //return YieldEnumerator;
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion

        #region Enumerators

        private IEnumerator<T> YieldEnumerator
        {
            get
            {
                var current = _head;
                while (current != null)
                {
                    yield return current.Value;
                    current = current.Next;
                }
            }
        }

        private class LinkedListEnumerator<X> : IEnumerator<X>
        {
            private readonly Node<X> _head;
            private Node<X> _current;<commit_msg>Convert based on linked list stack's enumerator to struct<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace Basics.Structures
{
    public class StackOnList<T> : IStack<T>
    {
        private class Node<X>
        {
            public X Value { get; set; }
            public Node<X> Next { get; set; }
        }

        private int _size = 0;
        private Node<T> _head = null;

        /// <summary>
        /// Pushes value to the stack.
        /// </summary>
        public void Push(T value)
        {
            _size++;
            _head = new Node<T>
            {
                Value = value,
                Next = _head
            };
        }

        /// <summary>
        /// Pops value out of the stack.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown when stack is empty.</exception>
        public T Pop()
        {
            if (_head == null)
                throw new InvalidOperationException("Stack is empty.");

            _size--;
            var current = _head;
            _head = _head.Next;
            return current.Value;
        }

        /// <summary>
        /// Checks whether stack is empty.
        /// </summary>
        public bool IsEmpty
        {
            get { return _head == null; }
        }

        /// <summary>
        /// Returns size of the stack.
        /// </summary>
        public int Size
        {
            get { return _size; }
        }

        #region IEnumerable Members

        public IEnumerator<T> GetEnumerator()
        {
            return new LinkedListEnumerator<T>(_head);
            //return YieldEnumerator;
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion

        #region Enumerators

        private IEnumerator<T> YieldEnumerator
        {
            get
            {
                var current = _head;
                while (current != null)
                {
                    yield return current.Value;
                    current = current.Next;
                }
            }
        }

        private struct LinkedListEnumerator<X> : IEnumerator<X>
        {
            private readonly Node<X> _head;
            private Node<X> _current;
{'fraction_non_alphanumeric': 0.09465020576131687, 'fraction_numerical': 0.00043318171973142733, 'mean_word_length': 1.1772748703441773, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, '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': '5030185', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1171, 'n_words': 319}