⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 并行计算里
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int[] A ={ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, int.MaxValue };
            int[] B ={ 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, int.MaxValue };
            int[] C = new int[A.Length + B.Length - 2];
            int i = 0;
            int j = 0;
            for (int k = 0; k < C.Length; k++)
            {
                if (A[i] < B[j])
                {
                    C[k] = A[i];
                    i++;
                }
                else
                {
                    C[k] = B[j];
                    j++;
                }
            }
            for (int k = 0; k < C.Length; k++)
            {
                this.label3.Text += C[k].ToString() + " ";
            }

        }

        private int[] Rank(int[] A, int[] B)
        {
            int[] temp = new int[A.Length];
            for (int i = 0; i < A.Length; i++)
            {
                int j = 0;
                for (int k = 0; k < B.Length; k++)
                {
                    if (A[i] >= B[k])
                    {
                        j++;
                    }
                }
                temp[i] = j;
            }
            return temp;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int[] A ={ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 };
            int[] B ={ 4, 6, 8, 10, 12, 14, 16, 18, 20, 22 };
            int[] C = new int[A.Length + B.Length];
            int[] AA = Rank(A, A);
            int[] AB = Rank(A, B);
            int[] BA = Rank(B, A);
            int[] BB = Rank(B, B);
            int[] AAB = new int[AA.Length];
            for (int i = 0; i < AAB.Length; i++)
            {
                AAB[i] = AA[i] + AB[i] - 1;
            }
            int[] BAB = new int[BB.Length];
            for (int j = 0; j < BAB.Length; j++)
            {
                BAB[j] = BA[j] + BB[j] - 1;
            }
            for (int i = 0; i < AAB.Length; i++)
            {
                C[AAB[i]] = A[i];
            }
            for (int j = 0; j < BAB.Length; j++)
            {
                C[BAB[j]] = B[j];
            }
            for (int i = 0; i < C.Length; i++)
            {
                this.label3.Text += C[i].ToString() + " ";
            }
            

        }

        private void button3_Click(object sender, EventArgs e)
        {
            Merge mg = new Merge();
            Thread thread1 = new Thread(mg.MergeA);
            Thread thread2 = new Thread(mg.MergeB);
            thread1.Start();
            thread2.Start();
            thread1.Join();
            thread2.Join();
            for (int i = 0; i < mg.C.Length; i++)
            {
                this.label3.Text += mg.C[i].ToString() + " ";
            }


        }
    }
    public class Merge
    {
        private int[] m_A ={ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 };
        private int[] m_B ={ 4, 6, 8, 10, 12, 14, 16, 18, 20, 22 };
        private int[] m_C;
        public int[] C
        {
            get
            {
                return this.m_C;
            }
        }

        private int[] Rank(int[] A, int[] B)
        {
            int[] temp = new int[A.Length];
            for (int i = 0; i < A.Length; i++)
            {
                int j = 0;
                for (int k = 0; k < B.Length; k++)
                {
                    if (A[i] >= B[k])
                    {
                        j++;
                    }
                }
                temp[i] = j;
            }
            return temp;
        }

        public Merge()
        {
            this.m_C = new int[this.m_A.Length + this.m_B.Length];
        }

        public void MergeA()
        {
            int[] AA = Rank(this.m_A, this.m_A);
            int[] AB = Rank(this.m_A, this.m_B);
            int[] AAB = new int[AA.Length];
            for (int i = 0; i < AAB.Length; i++)
            {
                AAB[i] = AA[i] + AB[i] - 1;
            }
            for (int i = 0; i < AAB.Length; i++)
            {
                this.m_C[AAB[i]] = this.m_A[i];
            }
        }
        public void MergeB()
        {
            int[] BA = Rank(this.m_B, this.m_A);
            int[] BB = Rank(this.m_B, this.m_B);
            int[] BAB = new int[BB.Length];
            for (int j = 0; j < BAB.Length; j++)
            {
                BAB[j] = BA[j] + BB[j] - 1;
            }
            for (int j = 0; j < BAB.Length; j++)
            {
                this.m_C[BAB[j]] = this.m_B[j];
            }
        }


    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -