Ejemplo n.º 1
0
        public int[] allEle(int j)
        {
            hole tmp = head;
            int  s   = size();

            int[] arr = new int[s];
            if (j == 0)
            {
                for (int i = 0; i < s; i++)
                {
                    arr[i] = tmp.get_start();
                    tmp    = tmp.get_next();
                }
            }
            else if (j == 1)
            {
                for (int i = 0; i < s; i++)
                {
                    arr[i] = tmp.get_end();
                    tmp    = tmp.get_next();
                }
            }
            else if (j == 2)
            {
                for (int i = 0; i < s; i++)
                {
                    arr[i] = tmp.get_size();
                    tmp    = tmp.get_next();
                }
            }


            return(arr);
        }
Ejemplo n.º 2
0
        public hole findByStart(int i)
        {
            hole tmp = head;

            while (tmp.get_start() != i)
            {
                tmp = tmp.get_next();
            }
            return(tmp);
        }
Ejemplo n.º 3
0
        public void printHoles()
        {
            mMem.sort(0);
            hole holes = mMem.get_hHole();
            int  size  = mMem.size();

            for (int i = 0; i < size; i++)
            {
                int start = holes.get_start();
                int end   = holes.get_end();
                listBox1.Items.Add(mTxt1Hole + start + "    to    " + end);
                holes = holes.get_next();
            }
        }
Ejemplo n.º 4
0
        public void swap(hole tmp, hole 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.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            bool ok = true;

            disHole();
            listBox1.Items.Clear();
            listBox2.Items.Clear();
            string proName = textBox1.Text;
            int    proSize = Convert.ToInt32(numericUpDown3.Value);

            if (comboBox1.Text == "First Fit")
            {
                int[] arr     = mMem.allEle(2);
                int   holeNum = mMem.size();
                for (int i = 0; i < holeNum; i++)
                {
                    if (arr[i] >= proSize)
                    {
                        mNumProcess++;
                        hole tmp      = mMem.findBySize(arr[i]);
                        int  proStart = tmp.get_start();
                        int  proEnd   = proStart + proSize - 1;
                        mPro.Add(proName, proStart, proSize, tmp.get_holeNum());
                        int tmpSize = tmp.get_size();
                        int newSize = tmpSize - proSize;
                        if (newSize != 0)
                        {
                            tmp.set_start(proStart + proSize);
                            tmp.set_size(tmpSize - proSize);
                        }
                        else
                        {
                            mMem.remove(tmp);
                            mHoleNum--;
                        }
                        ok = false;
                        break;
                    }
                    else
                    {
                        ok = true;
                    }
                }
            }
            else if (comboBox1.Text == "Best Fit")
            {
                mMem.sort(2);
                int[] arr     = mMem.allEle(2);
                int   holeNum = mMem.size();
                for (int i = 0; i < holeNum; i++)
                {
                    if (arr[i] >= proSize)
                    {
                        mNumProcess++;
                        hole tmp      = mMem.findBySize(arr[i]);
                        int  proStart = tmp.get_start();
                        int  proEnd   = proStart + proSize - 1;
                        mPro.Add(proName, proStart, proSize, tmp.get_holeNum());
                        int tmpSize = tmp.get_size();
                        int newSize = tmpSize - proSize;
                        if (newSize != 0)
                        {
                            tmp.set_start(proStart + proSize);
                            tmp.set_size(tmpSize - proSize);
                        }
                        else
                        {
                            mMem.remove(tmp);
                            mHoleNum--;
                        }
                        ok = false;
                        break;
                    }
                    else
                    {
                        ok = true;
                    }
                }
            }
            else if (comboBox1.Text == "Worst Fit")
            {
                mMem.sort(2);
                int[] arr     = mMem.allEle(2);
                int   holeNum = mMem.size();
                if (holeNum == 0)
                {
                    ;
                }
                else if (arr[holeNum - 1] >= proSize)

                {
                    mNumProcess++;
                    hole tmp      = mMem.findBySize(arr[holeNum - 1]);
                    int  proStart = tmp.get_start();
                    int  proEnd   = proStart + proSize - 1;
                    mPro.Add(proName, proStart, proSize, tmp.get_holeNum());
                    int tmpSize = tmp.get_size();
                    int newSize = tmpSize - proSize;
                    if (newSize != 0)
                    {
                        tmp.set_start(proStart + proSize);
                        tmp.set_size(tmpSize - proSize);
                    }
                    else
                    {
                        mMem.remove(tmp);
                        mHoleNum--;
                    }
                    ok = false;
                }
                else
                {
                    ok = true;
                }
            }
            if (ok)
            {
                mErrorMsg = "Thers is no enough memory";
                MessageBox.Show(mErrorMsg);
            }
            textBox1.Text = "p" + mNumProcess;

            printPro();
        }
Ejemplo n.º 6
0
        public void sort(int sel)
        {
            hole tmp = head;
            int  n = size();
            int  x, y;

            if (sel == 0)
            {
                for (x = 0; x < n; x++)
                {
                    hole tmp2 = tmp.get_next();
                    for (y = 0; y < n - x - 1; y++)
                    {
                        int c  = tmp.get_start();
                        int nn = tmp2.get_start();
                        if (c > nn)
                        {
                            swap(tmp, tmp2);
                        }

                        tmp2 = tmp2.get_next();
                    }
                    tmp = tmp.get_next();
                }
            }
            else if (sel == 1)
            {
                for (x = 0; x < n; x++)
                {
                    hole tmp2 = tmp.get_next();
                    for (y = 0; y < n - x - 1; y++)
                    {
                        int c  = tmp.get_end();
                        int nn = tmp2.get_end();
                        if (c > nn)
                        {
                            swap(tmp, tmp2);
                        }

                        tmp2 = tmp2.get_next();
                    }
                    tmp = tmp.get_next();
                }
            }
            else if (sel == 2)
            {
                for (x = 0; x < n; x++)
                {
                    hole tmp2 = tmp.get_next();
                    for (y = 0; y < n - x - 1; y++)
                    {
                        int c  = tmp.get_size();
                        int nn = tmp2.get_size();
                        if (c > nn)
                        {
                            swap(tmp, tmp2);
                        }

                        tmp2 = tmp2.get_next();
                    }
                    tmp = tmp.get_next();
                }
            }
        }