Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me i need too much i wantto sort function my code is

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

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




        public void Our_sort(UInt32[] array, int p, int q, int digit)
        {

            int i=p,j=q;
            UInt32 t;
            if (q <= p || digit > 32) return;
            while (j != i)
            {//hocam burda bitwise dediğinizi  tanımlamak istiyorum dediğiniz şekilde((bitwise(array[i], digit) bu array[i] & 536870912 anlamına gelsin nasıl denir
                while ((array[i] & (UInt32)Math.Pow(2, 32 - digit)) == 0 && (i < j))  i++;
                while ((array[j] & (UInt32)Math.Pow(2, 32 - digit)) == 0 && (j > i))  j--;
                t = array[i]; array[i] = array[j]; array[j] = t;
            }
            if ((array[q] & (UInt32)Math.Pow(2, 32-digit) ) == 0) j++;
            Our_sort(array,p,j-1,digit+1);
            Our_sort(array,j,q,digit+1);


  }
        public static void Main(string[] args) {

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

sorter.Our_sort(array, 0, 4, 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");
}
}
}



how can i run it i have i wrong with something
Posted

t's difficult to know where to start with that...
First off, why is Main a static member of the Sort class? It should be a member of the Program class - so put it back where it belongs.

Secondly, why is Our_sort an instance member of the Sort class when you don't use any of the other instance members in it (or indeed at all)? Make it a static member if it doesn't need the this reference.

Thirdly, I have absolutely no idea what you are trying to make this code do, but it fails because the index i gets bigger than the number of elements in your array. Why it does that, I don't know - I am not spend too much time running it and working that output, since it is your homework, not mine.

Fourthly, if you want me to look at code, indent it correctly (VS will do that for you if you press CTRL+K, CTRL+D) and use sensible names for variables - p and q do not help me to know what you are doing.

So, it's over to you. What I would suggest is that you start by using the debugger - put a breakpoint on the line
sorter.Our_sort(array, 0, 4, 1);
and step into the method. Step though and see what is going on - you have very few elements in your array, so it shouldn't take you long to work out what should be happening and compare that to what actually does. That will give you an idea what you have done wrong, and hopefully teach you the rudiments of debugging for yourself.
 
Share this answer
 
Your array has 4 elements but you are checking for
VB
while (j != i)
and passing in
C#
sorter.Our_sort(array, 0, 4, 1);

You are then trying to access array[4] - which doesn't exist.
Arrays start at index 0 ... i.e. the first element is array[0], the 2nd is array[1]
Try changing your '4's to '3'. At least you'll be able to run the code.

As for the sort function actually working have a look at
http://www.dotnetperls.com/sort[^]
 
Share this answer
 

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