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); }
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++; }
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; } }
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; } }
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(); } }
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); }
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(); } }
public LinkElem(T elem) { this.elem = elem; next = null; }
public LinkElem(LinkElem <T> nextelem, T elem) { this.elem = elem; next = nextelem; }
public LinkElem(LinkElem <T> a) { next = a; }
public LinkElem() { next = null; }
public LinkStack(T elem) { _isEmpty = false; _head = new LinkElem <T>(elem); }