Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp18
- {
- class Program
- {
- static void Main(string[] args)
- {
- ListLinked list = new ListLinked();
- list.Add(5);
- list.Add(4);
- list.Add(10);
- list.Add(550);
- list.Add(1);
- foreach (int i in list)
- {
- Console.WriteLine(i);
- }
- Console.ReadKey();
- }
- }
- class ListLinked : IEnumerable<int>
- {
- private Node _root;
- public int Count { get; private set; }
- public void Add(int value)
- {
- Node curNode = _root;
- if (curNode == null)
- {
- _root = new Node(value, null);
- }
- else
- {
- Node newNode = new Node(value, null);
- newNode.Next = curNode;
- _root = newNode;
- }
- }
- public IEnumerator<int> GetEnumerator()
- {
- Node timeNode = _root;
- while (timeNode != null)
- {
- yield return timeNode.Data;
- timeNode = timeNode.Next;
- }
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- throw new NotImplementedException();
- }
- }
- class Node
- {
- public Node Next;
- public int Data;
- public Node(int data, Node next)
- {
- Next = next;
- Data = data;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment