/// <summary> /// Add an element to the top of the Stack. /// </summary> /// <param name="data"></param> public void Push(T data) { SGLNode <T> SGLNode = new SGLNode <T>(data); if (Top == null) { Top = SGLNode; } else { Top.SetPrevious(SGLNode); SGLNode.SetNext(Top); Top = SGLNode; } Size = Size + 1; }
private SGLNode <T> Reverse(SGLNode <T> SGLNode) { SGLNode <T> prev = null; SGLNode <T> current = SGLNode; SGLNode <T> next = null; while (current != null) { next = current.GetNext(); current.SetNext(prev); prev = current; current = next; } SGLNode = prev; return(SGLNode); }
public void AppendToTail(T data) { SGLNode <T> node = new SGLNode <T>(data); if (Head == null || Tail == null) { Head = node; Tail = node; } else { Tail.SetNext(node); node.SetPrevious(Tail); Tail = node; } }
public void AppendToHead(T data) { SGLNode <T> node = new SGLNode <T>(data); if (Head == null || Tail == null) { Head = node; Tail = node; } else { Head.SetPrevious(node); node.SetNext(Head); Head = node; } }
/// <summary> /// Used to add an element ot the next most position of the Queue. /// </summary> /// <param name="data"></param> public void Enqueue(T data) { SGLNode <T> SGLNode = new SGLNode <T>(data); if (Front == null || Back == null) { Front = SGLNode; //Front.SetNext(Back); Back = SGLNode; } else { Back.SetNext(SGLNode); Back = SGLNode; } Size = Size + 1; }