c#排序问题请立即帮忙 [英] c# sorting problem immediately help please

查看:54
本文介绍了c#排序问题请立即帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

namespace DS
{
    class Sort
    {
        public String strYour_name = "Çağrı TAÇYİLDİZ";
        public long Your_number = 1502510097; //okul numarası;

        public void Our_sort(UInt32[] array, int p, int q, int digit)
        {
                 // 132= 10000100    00001001
                //14 =   00001100    00001100
               //2 =     00000010    00000010
              //9 =      00001001    10000100
            if (array == null)
                return;
            int i = p;
            int j = q;
            while (i <= j)
            {
                while (i<=q && FindBinaryValue(array[i])[digit] == '0')
                    i++;
                while (j>=p && FindBinaryValue(array[j])[digit] != '0')
                    j--;
                if (i <= j)
                {
                    uint tmp = array[i];
                    array[i++] = array[j];
                    array[j--] = tmp;
                }
            }
            if (j > p)
            {
                Our_sort(array, p, j,digit+1);
            }
            if (i < q)
            {
                Our_sort(array, i, q,digit+1);
            }
        }
        public string FindBinaryValue(uint a)
        {
            var st = Convert.ToString(a, 2);
            return st.PadLeft(8, '0');
        }
    }
}







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

namespace DS
{
    class Program
    {
        public static void Main(string[] args)
        {

            UInt32[] array = new UInt32[4] { 132, 2, 14, 9 };
            Sort sorter = new Sort();

            sorter.Our_sort(array, 0, 3, 1);

            Console.WriteLine("Siralamadan sonra array su sekilde: ");
            Console.Write("[");
            for (int i = 0; i < array.Length - 1; i++)
            {
                Console.Write(array[i] + ", ");
            }
            Console.Write(array[array.Length - 1] + "]\n");
        }

    }
}







请帮助我排序错误排序我怎么能修复它帮助请我想做它增加排序2,9,14,132




please help my sort make wrong sorting how can i repair it help please i wanna do it increasing sorting 2,9,14,132

推荐答案

首先仔细看看:

Array.Sort [ ^ ]



然后考虑一下你在这里做了什么:

Start by taking a close look at:
Array.Sort[^]

Then consider what you are actually doing here:
public string FindBinaryValue(uint a)
{
 var st = Convert.ToString(a, 2);
 return st.PadLeft(8, ''0'');
}



a 是值的二进制表示,你返回的不是,它' 'sa string。



看起来你正在实施 Quicksort [ ^ ]在c#中,并转换 a 到一个字符串你正在制作一个非常大的O。



祝你好运

Espen Harlinn


a is a binary representation of the value, what you return is not, it''s a string.

It looks like you are implementing the Quicksort[^] in c#, and by converting a to a string you''re making a very big "O".

Best regards
Espen Harlinn


相信我:请立即帮助

对你的情况没有帮助,一遍又一遍地发布相同的代码,微小的变化,而不是试图找出问题所在。



正如我上次所说:使用调试器。弄清楚应该发生什么,并按照代码来了解发生了什么。然后看看你能否发现原因。它可能比你重复发布花费更少的时间,可能意味着你可以按时交作业。



如果你试着调试它,来吧提出一个具体的问题,而不是帮助!它不起作用!他们会尽力帮助你 - 但你必须首先尝试帮助自己!
Trust me on this: "immediately help please"
Does not help your case, nor does posting the same code over and over again, with minor changes and not trying to work out what the problem is yourself.

As I said last time: Use the debugger. Work out what should happen and follow the code through to find out what does happen. Then look to see if you can spot why. It will probably take you less time than posting repeatedly, and may mean that you get to hand your homework in on time.

If you try to debug it, and come up with a concrete question instead of "HELP! It doesn''t work!" they we will try to help you - but you have to try to help yourself first!


这篇关于c#排序问题请立即帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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