Пример #1
0
 /* LIST OF FUCNTIONS
  *
     *  list.insert("6"); CREAT AN ITEM
        list.insertInto(10, "7"); INSERT INTO LIST POSITION
        list.insertIntoValue("7","8"); INSERT INTO POSITION WITH A PRE-DETERMINED VALUE
        list.ChangeBetween(1, 2); CHANGE BETWEEN NODES WITHIN TWO POSITIONS
        list.Organize(List list);
     *  list.write(); WRITE THE NODES IN CONSOLE
  *
  */
 static void Main(string[] args)
 {
     //Code
     List list = new List();
     list.RandomValues(max, list);
     list.Organize(list);
     while(list.number < 300)
     {
         list.RandomValues(5, list);
         list.Organize(list);
     }
     list.write();
     Console.WriteLine("Quanto tempo demorou esta caralha: {0}", list.stopwatch.Elapsed);
     Console.WriteLine("Quantas trocas: {0}", list.trocas);
     Console.Read();
 }
Пример #2
0
        public void RandomValues(int max, List list)
        {
            Random random = new Random();
            int randomNumber = random.Next(0, 999+number);

            for(int i=0;i<max-4;i++)
            {
                list.insert(randomNumber.ToString());
                randomNumber = random.Next(0, 999+number);
            }
        }
Пример #3
0
        public void Organize(List list)
        {
            stopwatch.Start();
            int troca = 0;
            int comp=0;
            int length=list.number;

            for(int i=length;i>0;i--)
            {
                for (int j=0;j<i; j++)
                {
                    comp++;
                    Node actual=FindItem(j);
                    Node next=actual.next;
                    int counts=0;
                    if(int.Parse(actual.valor)>int.Parse(next.valor))
                    {
                        counts++;
                        ChangeBetween(j, j+counts);
                        actual=FindItem(j+counts);
                        next=actual.next;
                        troca++;
                    }
                    else if(int.Parse(actual.valor)==int.Parse(next.valor))
                    {
                        actual = FindItem(j + counts);
                        next = actual.next;
                        troca++;
                    }
                    else
                    {
                        next=next.next;
                    }
                }
            }
            trocas = troca;
            stopwatch.Stop();
        }
Пример #4
0
 public void QuickSort(List list,int left,int right)
 {
     if (left < right)
     {
         int pivot = Noded(list, 0, number);
         if (pivot > 1)
         {
             QuickSort(list, left, pivot - 1);
         }
         if (pivot + 1 < right)
         {
             QuickSort(list, pivot + 1, right);
         }
     }
 }
Пример #5
0
        public int Noded(List list,int left,int right)
        {
            Node pivot = Head;
            Node LeftAnchor = FindItem(left);
            Node RightAnchor = FindItem(left);
            while (true)
            {
                while (LeftAnchor._intvalor < pivot._intvalor)
                {
                    left++;
                    LeftAnchor = FindItem(left);
                }
                while (RightAnchor._intvalor > pivot._intvalor)
                {
                    right++;
                    RightAnchor = FindItem(right);
                }

                if (left < right)
                {
                    Node Copy = RightAnchor.ShallowCopy();
                    RightAnchor = LeftAnchor;
                    LeftAnchor = Copy;
                }
                else
                {
                    return right;
                }
            }
        }