public void Delete(T value) { SimpleNode <T> temp = _head; if (_head == null) { return; } do { if (temp.GetValue().Equals(value)) { if (temp == _head) { if (Length() == 1) { _head = null; } } temp.SetValue(temp.GetNext().GetValue()); if (temp.GetNext() == _head) { _head = temp; } temp.SetNext(temp.GetNext().GetNext()); break; } temp = temp.GetNext(); }while(temp != _head); }
public void testPop() { Stack <int> tester = new Stack <int>(); tester.Push(0); tester.Push(1); tester.Push(2); SimpleNode <int> popped = tester.Pop(); Assert.AreEqual(popped.GetValue(), 2); popped = tester.Pop(); Assert.AreEqual(popped.GetValue(), 1); Assert.AreEqual(tester.Size(), 1); popped = tester.Pop(); Assert.AreEqual(popped.GetValue(), 0); Assert.Null(tester.Pop()); }
public SimpleNode <T> Search(T value) { SimpleNode <T> temp = _head; while (temp != null) { if (temp.GetValue().Equals(value)) { break; } temp = temp.GetNext(); } return(temp); }
public SimpleNode <T> Search(T value) { SimpleNode <T> temp = _head; if (_head == null) { return(null); } do { if (temp.GetValue().Equals(value)) { return(temp); } temp = temp.GetNext(); }while(temp != _head); return(null); }
public void Append(T value) { if (_head == null) { _head = new SimpleNode <T>(value); _head.SetNext(_head); return; } T headCopy = _head.GetValue(); SimpleNode <T> headNextCopy = _head.GetNext(); _head.SetValue(value); SimpleNode <T> insert = new SimpleNode <T>(headCopy); _head.SetNext(insert); insert.SetNext(headNextCopy); _head = insert; }
public void Delete(T value) { SimpleNode <T> temp = _head; SimpleNode <T> prev = null; while (temp != null) { if (temp.GetValue().Equals(value)) { if (temp == _head) { _head = temp.GetNext(); } else { prev.SetNext(temp.GetNext()); } break; } prev = temp; temp = temp.GetNext(); } }