article search result of 'list' : 1

  1. 2010.12.06 [c#] 간단한 Generic List (221)

[c#] 간단한 Generic List

    public class GenericList<T>
    {
        private class Node
        {
            private Node next;
            private T data;
            public Node(T t)
            {
                next = null;
                data = t;
            }
            public Node Next
            {
                get { return next; }
                set { next = value; }
            }
            public T Data
            {
                get { return data; }
                set { data = value; }
            }
        }

        private Node head;
        public GenericList()
        {
            head = null;
        }

        public void Add(T t)
        {
            Node n = new Node(t);
            n.Next = head;
            head = n;
        }

        public IEnumerator<T> GetEnumerator()
        {
            Node current = head;
            while (current != null)
            {
                yield return current.Data;
                current = current.Next;
            }
        }
    }

 

private 클래스 Node 와 그를 이용한 IEnummerator 구현 –> 제네릭 리스트 구현

 

참고 : (미친바바’s)  http://blog.naver.com/baba1092?Redirect=Log&logNo=130093943245

Yamecoder 야매코더_
C# 2010.12.06 11:31
Powerd by Tistory, designed by criuce
rss