public void Add(int elem) { MyListItem <int> newElem = new MyListItem <int>(elem); if (startElem == null) { startElem = newElem; } else { GetItem(Count - 1).nextElem = newElem; } }
public MyListItem <int> GetItem(int index) { if (Count == 0 || index >= Count) { throw new ArgumentOutOfRangeException(); } MyListItem <int> item = startElem; for (int i = 0; i < index; i++) { item = item.nextElem; } return(item); }
public void RemoveAt(int index) { if (index == 0) { if (startElem.nextElem == null) { startElem = null; } else { startElem = startElem.nextElem; } } else if (index == Count - 1) { GetItem(index - 1).nextElem = null; } else { GetItem(index - 1).nextElem = GetItem(index + 1); } }
public bool Remove(int elem) { if (Count == 0) { return(false); } for (int i = 0; i < Count; i++) { if (elem.Equals(this[i])) { if (i == 0) { if (startElem.nextElem == null) { startElem = null; } else { startElem = startElem.nextElem; } } else if (i == Count - 1) { GetItem(i - 1).nextElem = null; } else { GetItem(i - 1).nextElem = GetItem(i + 1); } return(true); } } return(false); }