Ejemplo n.º 1
0
        // Sorting algorithms-- Self Explanatory since the structure is the same as the actual algorithm

        public void BubbleSort(Func <Robot.IPointable, Robot.IPointable, bool> sortOrder) //Sort order is passed as a func
        {
            int size = r.Elements.Count;

            Robot._Pointer ppass = r.createPointer("Size-Pass", r.Elements[size - 1]); //This creates pointers to be animated
            for (int pass = 1; pass < size; pass++)
            {
                ppass.setIndex(r.Elements[size - pass]);
                Robot._Pointer pi = r.createPointer("I", r.Elements[0]);
                for (int i = 0; i < size - pass; i++)
                {
                    pi.setIndex(r.Elements[i]);
                    if (sortOrder.Invoke(r.Elements[i], r.Elements[i + 1]))
                    {
                        r.Switch(r.Elements[i].value, r.Elements[i + 1].value);
                    }
                }
                pi.Remove(); //Remove pointer when sorting animation is done
            }
            ppass.Remove();
            MessageBox.Show("Sorted!", "BubbleSort", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }