Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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');
        }
    }
}


C#
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");
        }

    }
}



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

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 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
 
Share this answer
 
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!
 
Share this answer
 
Comments
oooozzzzi 19-Dec-12 7:38am    
ok you are right but i am a erasmus student i saw c an python not c# so i couldnt run the program because of not my algortihm my syntax error now i runned it thanks again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900