Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#1.0 C#2.0 C#3.0 C# C#4.0
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");
        }
 
    }
}
 

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 19-Dec-12 1:00am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
Comments
oooozzzzi at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 446
1 OriginalGriff 380
2 Yogesh Kumar Tyagi 304
3 Prakriti Goyal 200
4 Maciej Los 165
0 OriginalGriff 6,472
1 Sergey Alexandrovich Kryukov 5,404
2 Maciej Los 3,434
3 Peter Leow 3,259
4 DamithSL 2,495


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 19 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100