Ejemplo n.º 1
0
        public void swap(process tmp, process tmp2)
        {
            int tmpHN    = tmp2.get_holeNum();
            int tmpStart = tmp2.get_start();
            int tmpSize  = tmp2.get_size();
            int tmpEnd   = tmp2.get_end();

            tmp2.set_start(tmp.get_start());
            tmp2.set_size(tmp.get_size());
            tmp2.set_holeNum(tmp.get_holeNum());
            tmp2.set_end(tmp.get_end());
            tmp.set_start(tmpStart);
            tmp.set_size(tmpSize);
            tmp.set_holeNum(tmpHN);
            tmp.set_end(tmpEnd);
        }
Ejemplo n.º 2
0
        private void listBox2_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int    ind          = listBox2.IndexFromPoint(e.X, e.Y);
            string tmp          = listBox2.Items[ind].ToString();
            int    indexOfSpace = tmp.IndexOf(" ", 0);
            string str          = tmp.Substring(0, indexOfSpace);

            listBox1.Items.Clear();
            listBox2.Items.Clear();
            process p        = mPro.findByName(str);
            int     holeNum  = p.get_holeNum();
            hole    h        = mMem.findByHoleNum(holeNum);
            int     proEnd   = p.get_end();
            int     proStart = p.get_start();
            int     proSize  = p.get_size();

            mMem.sort(0);
            int[] startArr = mMem.allEle(0);
            int[] endArr   = mMem.allEle(1);
            int   limit    = mMem.size();
            bool  ok       = true;

            for (int i = 0; i < limit; i++)
            {
                if (proEnd <= endArr[i] && proStart >= startArr[i])
                {
                    mErrorMsg = "already hole";
                    MessageBox.Show(mErrorMsg);
                    ok = false;
                    break;
                }
                else if ((i < limit - 1) &&
                         (proEnd + 1 == startArr[i + 1] && proStart - 1 == endArr[i]))
                {
                    hole tmpH  = mMem.findByStart(startArr[i]);
                    hole tmpH2 = mMem.findByStart(startArr[i + 1]);
                    tmpH.set_end(tmpH2.get_end());
                    tmpH.set_size(proSize + tmpH.get_size() + tmpH2.get_size());
                    mMem.removeByStart(startArr[i + 1]);
                    ok = false;
                    break;
                }
                else if (proEnd + 1 == startArr[i] || (proEnd >= startArr[i] && proEnd <= endArr[i]))
                {
                    hole tmpH = mMem.findByStart(startArr[i]);
                    tmpH.set_start(proStart);
                    tmpH.set_size(endArr[i] - proStart + 1);
                    ok = false;
                    break;
                }
                else if (proStart - 1 == endArr[i] || (proStart <= endArr[i] && proStart >= startArr[i]))
                {
                    hole tmpH = mMem.findByEnd(endArr[i]);
                    tmpH.set_end(proEnd);
                    tmpH.set_size(proEnd - startArr[i] + 1);
                    ok = false;
                    break;
                }
            }
            if (ok)
            {
                mMem.Add(mHoleNum, proStart, proSize);
                enProcess();
                mHoleNum++;
            }

            mPro.remove(p);
            if (mPro.size() == 0)
            {
                enHole();
            }
            printPro();
        }