Beispiel #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);
        }
Beispiel #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++;
 }
Beispiel #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;
     }
 }
Beispiel #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;
     }
 }
Beispiel #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();
     }
 }
Beispiel #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);
        }
Beispiel #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();
     }
 }
Beispiel #8
0
 public LinkElem(T elem)
 {
     this.elem = elem;
     next      = null;
 }
Beispiel #9
0
 public LinkElem(LinkElem <T> nextelem, T elem)
 {
     this.elem = elem;
     next      = nextelem;
 }
Beispiel #10
0
 public LinkElem(LinkElem <T> a)
 {
     next = a;
 }
Beispiel #11
0
 public LinkElem()
 {
     next = null;
 }
Beispiel #12
0
 public LinkStack(T elem)
 {
     _isEmpty = false;
     _head    = new LinkElem <T>(elem);
 }