Beispiel #1
0
        private string StringForm(string data)
        {
            SGLNode <T> current = Reverse(Top);
            SGLNode <T> topHold = current;

            while (current != null)
            {
                data    = data + current.ToString() + (current.GetNext() == null ? "" : ", ");
                current = current.GetNext();
            }
            Top = Reverse(topHold);
            return(data);
        }
Beispiel #2
0
 /// <summary>
 /// Take an element off the top of the Stack.
 /// </summary>
 public T Pop()
 {
     if (Top == null)
     {
         return(default(T));
     }
     else
     {
         SGLNode <T> Temporary = Top;
         Top  = Top.GetNext();
         Size = Size - 1;
         return(Temporary.GetData());
     }
 }
Beispiel #3
0
 /// <summary>
 /// Used take out the front element of the Queue.
 /// </summary>
 public T Dequeue()
 {
     if (Front == null || Back == null)
     {
         return(default(T));
     }
     else
     {
         SGLNode <T> Temporary = Front;
         Front = Front.GetNext();
         Size  = Size - 1;
         return(Temporary.GetData());
     }
 }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        private string StringForm(string data)
        {
            SGLArrayList <SGLNode <T> > SGLNodes = new SGLArrayList <SGLNode <T> >();
            SGLNode <T> temp  = Front;
            int         index = 0;

            while (temp != null)
            {
                SGLNodes.Add(temp);
                temp = temp.GetNext();
                data = data + SGLNodes.Get(index).ToString() + (temp == null ? "" : ", ");
                index++;
            }
            Front = SGLNodes.Get(0);
            return(data);
        }