예제 #1
0
        public CircularList(ICollection <CircularListEntry> col)
        {
            CircularListEntry help = new CircularListEntry();

            First = help;
            foreach (CircularListEntry entry in col)
            {
                help.Value = entry.Value;
                help.Key   = entry.Key;
                help.Next  = new CircularListEntry();
                help       = help.Next;
            }
            //help = First;
        }
예제 #2
0
 public void Add(CircularListEntry entry)
 {
     if (First != null)
     {
         CircularListEntry help = this.SearchKey(Count - 1);
         help.Next  = entry;
         entry.Next = First;
         entry.Key  = help.Key + 1;
     }
     else
     {
         First      = entry;
         First.Key  = 0;
         First.Next = First;
     }
 }
예제 #3
0
 public override string ToString()
 {
     if (First != null)
     {
         string            ans  = "";
         CircularListEntry help = First;
         ans += First.ToString() + " ";
         help = help.Next;
         while (help.Key != First.Key)
         {
             ans += help.ToString() + " ";
             help = help.Next;
         }
         return(ans);
     }
     else
     {
         return("Список пуст");
     }
 }
예제 #4
0
 public void Remove(CircularListEntry entry)
 {
     if (First != null)
     {
         CircularListEntry help = First;
         if (help.Value != entry.Value)
         {
             CircularListEntry last = help;
             help = help.Next;
             while (help.Key != First.Key)
             {
                 if (help.Value == entry.Value)
                 {
                     last.Next = help.Next;
                     for (int i = help.Key; i < Count - 1; i++)
                     {
                         help     = help.Next;
                         help.Key = i;
                     }
                     break;
                 }
                 else
                 {
                     last = help;
                     help = help.Next;
                 }
             }
         }
         else
         {
             this.SearchKey(this.Count - 1).Next = help.Next;
             First     = help.Next;
             First.Key = 0;
             for (int i = 0; i < Count - 1; i++)
             {
                 help     = help.Next;
                 help.Key = i;
             }
         }
     }
 }
예제 #5
0
        public CircularListEntry SearchKey(int key)
        {
            CircularListEntry help = First;

            if (key == help.Key)
            {
                return(help);
            }
            help = help.Next;
            while (help.Key != First.Key)
            {
                if (key == help.Key)
                {
                    return(help);
                }
                else
                {
                    help = help.Next;
                }
            }
            return(null);
        }
예제 #6
0
 public CircularList(CircularListEntry first)
 {
     First = first;
 }
예제 #7
0
 public CircularListEntry(int value)
 {
     Value = value;
     Next  = null;
 }
예제 #8
0
 public CircularListEntry()
 {
     Key   = 0;
     Value = 0;
     Next  = null;
 }