Exemple #1
0
 public bool DeleteFirstAndLast()
 {
     try
     {
         if (Head == null)
         {
             return(false);
         }
         if (Count <= 2)
         {
             Head = null;
         }
         else
         {
             SingleLinkNode <T> Temp = Head;
             while (Temp.Next.Next != Head)
             {
                 Temp = Temp.Next;
             }
             Temp.Next = Temp.Next.Next.Next;
             Head      = Temp.Next;
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #2
0
 public bool ReplaceFirstAndLast()
 {
     try
     {
         if (Head == null)
         {
             return(false);
         }
         if (Count < 2)
         {
             return(false);
         }
         else
         {
             SingleLinkNode <T> Temp = Head;
             while (Temp.Next != Head)
             {
                 Temp = Temp.Next;
             }
             T Swap = Head.Value;
             Head.Value = Temp.Value;
             Temp.Value = Swap;
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #3
0
 public bool Add(T newValue)
 {
     try
     {
         if (Count >= Limit && Limit != 0)
         {
             return(false);
         }
         if (Head == null)
         {
             Head      = new SingleLinkNode <T>(newValue);
             Head.Next = Head;
         }
         else
         {
             SingleLinkNode <T> Temp = Head;
             while (Temp.Next != Head)
             {
                 Temp = Temp.Next;
             }
             Temp.Next = new SingleLinkNode <T>(newValue, Head);
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #4
0
 public int Counter()
 {
     try
     {
         if (Head == null)
         {
             return(0);
         }
         if (Head.Next == Head)
         {
             return(1);
         }
         SingleLinkNode <T> Temp = Head;
         int counter             = 0;
         do
         {
             Temp = Temp.Next;
             counter++;
         }while (Temp != Head);
         return(counter);
     }
     catch
     {
         return(-1);
     }
 }
Exemple #5
0
 public int Counter()
 {
     try
     {
         if (Head == null)
         {
             return(0);
         }
         SingleLinkNode <T> Temp = Head;
         if (Temp.Next == Head)
         {
             return(1);
         }
         int Counter = 0;
         while (Temp.Next != Head)
         {
             Temp = Temp.Next;
             Counter++;
         }
         return(Counter);
     }
     catch
     {
         return(-1);
     }
 }
Exemple #6
0
        public override string ToString()
        {
            string Returning = string.Empty;

            if (Head != null)
            {
                SingleLinkNode <T> Temp = Head;
                do
                {
                    Returning += string.Format(" {0} ", Temp.Value);
                    Temp       = Temp.Next;
                }while (Temp != Head);
            }
            return(Returning);
        }
Exemple #7
0
 private SingleLinkNode <T> GetTail()
 {
     if (Head != null)
     {
         SingleLinkNode <T> Temp = Head;
         while (Temp.Next != Head)
         {
             Temp = Temp.Next;
         }
         return(Temp);
     }
     else
     {
         return(null);
     }
 }
Exemple #8
0
 public bool Add(T newValue)
 {
     try
     {
         if (Head == null)
         {
             Head      = new SingleLinkNode <T>(newValue, Head);
             Head.Next = Head;
         }
         else
         {
             Tail.Next = new SingleLinkNode <T>(newValue, Head);
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #9
0
 public LinkedCircularList(int Limit = 0)
 {
     Head       = null;
     this.Limit = Limit;
 }
Exemple #10
0
 public DoubleLinkNode(T Value, SingleLinkNode <T> Next = null, SingleLinkNode <T> Previous = null)
 {
     this.Value    = Value;
     this.Previous = Previous;
     this.Next     = Next;
 }
Exemple #11
0
 public SingleLinkNode(T Value, SingleLinkNode <T> Next = null)
 {
     this.Value = Value;
     this.Next  = Next;
 }