コード例 #1
0
        public void Add(int k, string mess)
        {
            if (Check(data, k) == false)
            {
                throw new ArgumentException();
            }
            else
            {
                SortedNode node = new SortedNode(k, mess);
                data[count] = node.key;
                s1[count]   = node.value;
                if (head == null)
                {
                    head = node;
                    tail = node;
                }
                else
                {
                    if (head.key > node.key)
                    {
                        node.Next = head;
                        tail      = head;
                        head      = node;
                    }
                    else if (head.key < node.key)
                    {
                        SortedNode curr  = head;
                        SortedNode curr1 = head;

                        if (head == tail)
                        {
                            head.Next = node;
                            tail      = node;
                        }
                        else if (node.key > tail.key)
                        {
                            tail.Next = node;
                            tail      = node;
                        }
                        else
                        {
                            for (int i = 0; curr.key < node.key && curr.Next.key > node.key; i++)
                            {
                                curr1 = curr;
                                curr  = curr.Next;
                            }
                            curr1.Next = node;
                            node.Next  = curr;
                        }
                    }
                }
                //Sort(data);
                count++;
            }
        }
コード例 #2
0
        public IEnumerator GetEnumerator()
        {
            SortedNode curr = head;

            for (int i = 0; i < count; i++)
            {
                string n = "[";
                n += Convert.ToString(curr.key);
                n += ", ";
                n += curr.value;
                n += "]";
                yield return(n);

                curr = curr.Next;
            }
        }
コード例 #3
0
 public int this[int key]
 {
     get
     {
         SortedNode current = head;
         for (int i = 0; i < key && current != null; i++)
         {
             current = current.Next;
         }
         return(current.key);
     }
     set
     {
         SortedNode current = head;
         current.key = value;
     }
 }
コード例 #4
0
 public int key1(SortedNode a)
 {
     return(a.key);
 }
コード例 #5
0
 public MySortedList()
 {
     head = null;
 }