我怎样才能运行这个C#代码?请帮助我!!我是初学者在编程 [英] How Can I Run This C# Code?Please Help Me!! Im Beginner At Programing

查看:53
本文介绍了我怎样才能运行这个C#代码?请帮助我!!我是初学者在编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace insertion_sort
{
    class Program
    {
        static int[] A;
        //int mid = 150;
        //static int[] R;
       // static int[] numbers;
        static Thread t1;
        static Thread t2;
        static Thread t3;
        static ThreadStart ts1;
        static ThreadStart ts2;
        static ThreadStart ts3;

        public static void insertion_sort1()
        {
            A = new int[100];

            Random r = new Random();
            for (int i = 0; i < 49; i++)
            {
                A[i] = r.Next(1, 100);
            }


            for (int i = 0; i <= 49; i++)
            {
                int j = i;

                while (j != 0 && A[j - 1] > A[j])
                {
                    int temp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = temp;

                    j--;
                }
            }
        }

        public static void insertion_sort2()
        {
            Random r = new Random();
            for (int i = 50; i < 99; i++)
            {
                A[i] = r.Next(1, 100);
            }

            for (int i = 50; i <= 99; i++)
            {
                int j = i;

                while (j != 0 && A[j - 1] > A[j])
                {
                    int temp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = temp;

                    j--;
                }
            }
        }

        static public void DoMerge()
        {
            int left = 0;
            int mid =50;
            int right = 99;
            A = new int[100];

            int[] temp = new int[150];
            int i, left_end, num_elements, tmp_pos;

            left_end = (mid - 1);
            tmp_pos = left;
            num_elements = (right - left + 1);

            while ((left <= left_end) && (mid <= right))
            {
                if (A[left] <= A[mid])
                    temp[tmp_pos++] = A[left++];
                else
                    temp[tmp_pos++] = A[mid++];
            }

            while (left <= left_end)
                temp[tmp_pos++] = A[left++];

            while (mid <= right)
                temp[tmp_pos++] = A[mid++];

            for (i = 0; i < num_elements; i++)
            {
                A[right] = temp[right];
                right--;
            }
        }

        


   
        static void Main(string[] args)
        {
          
            ts1 = new ThreadStart(insertion_sort1);
           
            ts2 = new ThreadStart(insertion_sort2);
       
            ts3 = new ThreadStart(DoMerge);


            t1 = new Thread(ts1);
            t2 = new Thread(ts2);
            t3 = new Thread(ts3);

            t1.Start();
            t2.Start();
            t3.Start();
            t3.Join();  

        }
    }
}

推荐答案

首先回到你的位置从那里复制代码并查找:只是从互联网上抓取代码而不知道它的作用是一种非常危险的方式继续。

请记住,除非你知道代码的作用是什么,运行它会让您的整个生命处于危险之中:它可以清除硬盘上的所有文件,将您的信用卡详细信息发送给作者,将垃圾邮件发送给您认识的所有人,或者只需订购比萨饼并在30分钟内将其发送给您。



作为一个甚至不知道如何编译和运行代码的初学者,你不应该真的这样做,只不过你将车钥匙放在点火和司机门一夜之间打开。



说实话,提交它作为你的功课不会让你获得好成绩:它可能会让你开始然而,抄袭课程。



Tr y并自己编写代码 - 你将学到更多东西!
Start by going back to where you copied the code from and looking there: just grabbing code from the internet without knowing what it does is a very dangerous way to proceed.
Bear in mind that unless you know what a chunk of code does, running it puts your whole life at risk: it could erase all the files on your hard drive, send your credit card details to the author, email spam to everyone you know, or just order a pizza and have it delivered to you in thirty minutes.

As a beginner who doesn't even know how to compile and run code you shouldn't really do this, any more than you would leave your car keys in the ignition and the drivers door open overnight.

And to be honest, submitting that as your homework is not going to get you a good grade: it might get you kicked off the course for plagiarism however.

Try and write the code yourself - you will learn a lot more!


这篇关于我怎样才能运行这个C#代码?请帮助我!!我是初学者在编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆