Ejemplo n.º 1
0
        private void ButtonSort_Click(object sender, EventArgs e)
        {
            CSNI.CreateAlgorithm();
            CSNI.SetData(CSNI.ConvertToString(CSNI.g_dataArray));
            string data = Marshal.PtrToStringAnsi(CSNI.GetData());

            CSNI.Sort(GetAlgIndexByName(Define.g_currentAlgorithm), Define.g_isASC);
            Flag.g_processing = true;
        }
Ejemplo n.º 2
0
        public async void UpdatePanelDetail(Panel panel, TextBox log)
        {
            try
            {
                Panel pnlGraphic2 = (Panel)panel.Controls["panelGraphic2"];
                Panel pnlGraphic1 = (Panel)panel.Controls["panelGraphic1"];

                Label lbl1       = new Label();
                Label lbl2       = new Label();
                Label lblCompare = new Label();

                lbl1.Width     = 40;
                lbl1.Height    = 30;
                lbl1.AutoSize  = false;
                lbl1.Name      = "label1";
                lbl1.TextAlign = ContentAlignment.MiddleCenter;
                lbl1.Location  = new Point(pnlGraphic1.Location.X + 10, pnlGraphic1.Height / 2 - lbl1.Height / 2);
                lbl1.BackColor = Color.Brown;
                lbl1.ForeColor = Color.White;

                lblCompare.Width     = 40;
                lblCompare.Height    = 30;
                lblCompare.BackColor = pnlGraphic1.BackColor;
                lblCompare.ForeColor = Color.Black;
                lblCompare.AutoSize  = false;
                lblCompare.Name      = "labelCompare";
                lblCompare.TextAlign = ContentAlignment.MiddleCenter;
                lblCompare.Location  = new Point(lbl1.Location.X + lbl1.Width + 10, pnlGraphic1.Height / 2 - lbl1.Height / 2);

                lbl2.Width     = 40;
                lbl2.Height    = 30;
                lbl2.AutoSize  = false;
                lbl2.Name      = "label2";
                lbl2.TextAlign = ContentAlignment.MiddleCenter;
                lbl2.Location  = new Point(lblCompare.Location.X + lblCompare.Width + 10, pnlGraphic1.Height / 2 - lbl1.Height / 2);
                lbl2.BackColor = Color.Gold;
                lbl2.ForeColor = Color.Black;

                //Add 3 labels to panelGraphic1
                pnlGraphic1.SuspendLayout();
                pnlGraphic1.Controls.Clear();
                pnlGraphic1.Controls.Add(lbl1);
                pnlGraphic1.Controls.Add(lbl2);
                pnlGraphic1.Controls.Add(lblCompare);
                pnlGraphic1.ResumeLayout();

                string   process      = Marshal.PtrToStringAnsi(CSNI.GetProcess());
                string[] processArray = process.Split(new char[] { ';' });
                for (int i = 0; i < processArray.Length; i++)
                {
                    Label lbl        = null;
                    int   startIndex = 0;
                    lbl2.Text = ((Label)pnlGraphic2.Controls["label" + i]).Text;
                    for (int j = 0; j < processArray[i].Length; j++)
                    {
                        if (processArray[i][j] == '[' || processArray[i][j] == '<')
                        {
                            startIndex = j;
                            continue;
                        }

                        if (processArray[i][j] == ']')
                        {
                            //Console.WriteLine(int.Parse(processArray[i].Substring(startIndex + 1, j - startIndex-1)));
                            pnlGraphic2.SuspendLayout();
                            lbl           = ((Label)pnlGraphic2.Controls[("label" + int.Parse(processArray[i].Substring(startIndex + 1, j - startIndex - 1)))]);
                            lbl.BackColor = Color.Brown;
                            lbl1.Text     = lbl.Text;
                            pnlGraphic2.ResumeLayout(true);

                            //Delay for viewing UI clearly
                            await Task.Delay(10000);
                        }

                        if (processArray[i][j] == '>')
                        {
                            string action = processArray[i].Substring(startIndex + 1, j - startIndex - 1);
                            if (action == "swap")
                            {
                                log.AppendText("Swap " + lbl1.Text + " with " + lbl2.Text + "\r\n");
                            }
                            else if (action == "noswap")
                            {
                                log.AppendText("Don't need to swap, go to next number\r\n");
                            }
                        }
                        if (lbl != null)
                        {
                            lbl.BackColor = Color.Teal;
                        }
                    }
                }
            }
            catch (Exception ex)
            { }
        }