예제 #1
0
        object ICloneable.Clone()
        {
            LinkElem <T> now = _head;
            int          i;
            LinkList <T> CloneList = new LinkList <T>();

            for (i = 0; i < _collElem; i++)
            {
                CloneList.Append(now.elem);
                now = now.next;
            }
            return(CloneList);
        }
예제 #2
0
 public void Append(T elem)
 {
     if (!_isEmpty)
     {
         _last.next = new LinkElem <T>(elem);
         _last      = _last.next;
     }
     else
     {
         _head    = new LinkElem <T>(elem);
         _last    = _head;
         _isEmpty = false;
     }
     _collElem++;
 }
예제 #3
0
 public void Push(T elem)
 {
     if (!_isEmpty)
     {
         LinkElem <T> OldHead = _head;
         _head      = new LinkElem <T>(elem);
         _head.next = OldHead;
         _collElem++;
     }
     else
     {
         _isEmpty  = false;
         _head     = new LinkElem <T>(elem);
         _collElem = 1;
     }
 }
예제 #4
0
 public void Add(T elem)
 {
     if (!_isEmpty)
     {
         _tail.next = new LinkElem <T>(elem);
         _tail      = _tail.next;
         _collElem++;
     }
     else
     {
         _head     = new LinkElem <T>(elem);
         _tail     = _head;
         _isEmpty  = false;
         _collElem = 1;
     }
 }
예제 #5
0
 public T Get(int index)
 {
     if ((index < _collElem) && (index > 0))
     {
         LinkElem <T> now = _head;
         int          i;
         for (i = 0; i < index; i++)
         {
             now = now.next;
         }
         return(now.elem);
     }
     else
     {
         throw new IndexOutOfRangeException();
     }
 }
예제 #6
0
        public int FindElem(T elem)
        {
            LinkElem <T> now = _head;
            int          i;

            for (i = 0; i < _collElem; i++)
            {
                if (now.elem.Equals(elem))
                {
                    return(i);
                }
                else
                {
                    now = now.next;
                }
            }
            return(-1);
        }
예제 #7
0
 public T Pop()
 {
     if (!_isEmpty)
     {
         T ReturnElem = _head.elem;
         _collElem--;
         if (_collElem != 0)
         {
             _head = _head.next;
         }
         else
         {
             _isEmpty = true;
         }
         return(ReturnElem);
     }
     else
     {
         throw new IndexOutOfRangeException();
     }
 }
예제 #8
0
 public LinkElem(T elem)
 {
     this.elem = elem;
     next      = null;
 }
예제 #9
0
 public LinkElem(LinkElem <T> nextelem, T elem)
 {
     this.elem = elem;
     next      = nextelem;
 }
예제 #10
0
 public LinkElem(LinkElem <T> a)
 {
     next = a;
 }
예제 #11
0
 public LinkElem()
 {
     next = null;
 }
예제 #12
0
 public LinkStack(T elem)
 {
     _isEmpty = false;
     _head    = new LinkElem <T>(elem);
 }