|
Okay. So my first attempt in sorting the strings using Radix Sort is a failure(The one with converting all strings into ASCII code).
Now, what i want to do is use the strings directly to sort them out using Radix Sort. Is there any available source code that can sort strings using Radix Sort? I already got one source code but I think it's implemented in Java. I don't have any time to make my own code since it will be passed on saturday(GMT +8:00).
One question though. What programming language that uses CharAt() method? Is that Java? If so, what is the equivalent method of that in C#?
|
|
|
|
|
gamer1127 wrote: What programming language that uses CharAt() method?
It could be an Extension Method.
gamer1127 wrote: what is the equivalent method of that in C#?
Just use an index: c = s [ i ]
|
|
|
|
|
gamer1127 wrote: CharAt() method? Is that Java?
Yes.
In C#, you can index a string as if it were an array. The elements are of type char , and of course read-only.
|
|
|
|
|
This is the source code that I got. It's a msd Radix sort:
public static void msd(String[] a)
{
msd(a, 0, a.Length, 0);
}
private static void msd(String[] a, int l, int r, int d)
{
int N = a.Length;
if (r <== l + 1) return;
int[] count = new int[256];
for (int i = 0; i < N; i++)
count[a[i].charAt(d) + 1]++;
for (int k = 1; k < 256; k++)
count[k] += count[k-1];
for (int i = 0; i < N; i++)
temp[count[a[i].charAt(d)]++] = a[i];
for (int i = 0; i < N; i++)
a[i] = temp[i];
for (int i = 1; i < 255; i++)
msd(a, l + count[i], l + count[i+1], d+1);
}
How will I revise this so I can use it in c#?
|
|
|
|
|
count[a[i].charAt(d) + 1] -> count[a[i][d] + 1]
|
|
|
|
|
I'm still having a problem with my string sorting. I always get the IndexOutOfRange exception during runtime.
How will I solve that?
public static void SortByLastName(ref string[] arrayOfLastNames, ref string[] arrayOfFirstNames, ref string[] arrayOfPlateNum, ref string[] arrayOfType, ref string[] arrayOfYear)
{
Console.Clear();
int vehicleCountInt = 0;
Console.WriteLine("SHOW DATABASE: SORTING BY LAST NAME\n");
using (StreamReader countVehicle = new StreamReader("vehiclecount.txt"))
{
vehicleCountInt = Int32.Parse(countVehicle.ReadLine());
}
using (StreamReader outputLastNames = new StreamReader("lastnames.txt"))
{
int[] b = new int[vehicleCountInt + 1]; ;
for (int i = 0; i < vehicleCountInt; i++)
{
arrayOfLastNames[i] = outputLastNames.ReadLine();
Console.WriteLine();
}
}
int N = arrayOfLastNames.Length;
int W = arrayOfLastNames[0].Length;
string[] temp = new string[vehicleCountInt];
for (int d = W - 1; d >= 0; d--)
{
int[] count = new int[vehicleCountInt];
for (int i = 0; i < N; i++)
{
count[arrayOfLastNames[i][d] + 1]++;
}
for (int k = 1; k < 256; k++)
{
count[k] += count[k - 1];
}
for (int i = 0; i < N; i++)
{
temp[count[arrayOfLastNames[i][d]]++] = arrayOfLastNames[i];
}
for (int i = 0; i < N; i++)
{
arrayOfLastNames[i] = temp[i];
Console.WriteLine("{0}", arrayOfLastNames[i]);
}
}
}
|
|
|
|
|
You don't need ref for those arrays, you're not assigning to them
But wait, how can you be sure that those arrays are long enough?
tip: always tell where you get the exception.
I suspect it happens here: arrayOfLastNames[i] = outputLastNames.ReadLine();
Since there is no guarantee that arrayOfLastNames is long enough (its length is unknown)
|
|
|
|
|
Ok..Is there a way on how to solve that problem? I'm thinking of declaring an array that is large enough for me to store those names.
|
|
|
|
|
I hope you aren't asking for a way to declare an array of a given size..
int[] b = new int[vehicleCountInt + 1]; is one such declaration, but probably 1 too big (why are you adding one?)
If you are asking how to assign to an array which is a function parameter, well, ref is used for exactly that purpose, but out may be sufficient. But this "problem" is as trivial as the first.
|
|
|
|
|
Well I'm referring to how will I solve the problem about the uncertainty of the array's size. I've declared 5 text files with 30 data inside. Now what my groupmate did was create a text file and put there the total number of data inside the text files, and that's the vehicleCount .
Now what I'm thinking is declare an array that has a definite size (say 50) which will hold the data inside the text file(the 30 predefined data and the user's additional inputs). Will this solve the problem about the IndexOutOfRange exception?
|
|
|
|
|
Declaring an array to be intentionally too big is not really nice
You could make it a List or read the file all at once and then split on newlines
|
|
|
|
|
Your right...It didn't solve the problem..I'm sticking to the original code that we created (having a text file that acts like a counter).
|
|
|
|
|
|
string strRaw = "Thisisastring";
char[] astrSorted = strRaw.ToCharArray().ToArray();
Array.Sort(astrSorted);
string strSorted = String.Empty;
foreach (char strChar in astrSorted)
{
strSorted += strChar;
}
eto try mo dn tong code nato
|
|
|
|
|
How to enable click event in Grid view, I am using class Libray project plase help.
modified on Wednesday, September 2, 2009 8:54 AM
|
|
|
|
|
Display the Properties tab in VS when focus is on the GridView, and click the Events button. Scroll to the 'Click' event and select the appropriate event; the designer will create stub code and navigate to the function so you can add your code.
|
|
|
|
|
hi,
how can i develop a patch for my win application. whenever i update some portion in my apps and then i have to always give the big setup to my client. it is very time consuming. so anyone can tell me how can i develop a patch for my apps that when i update any portion of apps then i will just create a path and give this path to my client and client will install easily. if is there any way then please tell me how can i do it.
tbhattacharjee
|
|
|
|
|
You can buy tools to do this, which actually do patch the binary.
You can also use winzip self extractor to deploy just the files needed to update an install.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Further to Christian's answer, a patch should only include changed files. If you can identify which files are changed, then the problem of building a patch is solved. If you are thinking of patching a single binary then there a potential problems. It is better to ship each component file in full.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Maybe NetDasm - A tool to disassemble and patch .NET assemblies[^] from here on CP will help. If that one does not suit search the articles for patch, there are several likely articles.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi
I have been trying to make a splash screen for my program in C#, i have tried a couple of tutorials in C# as well .. but to no success . !
i only need a simple figure to diplay for a while and than another form(My main Program ) should appear ..
how can i do this ?
Help will be highly appreciated
|
|
|
|
|
|
I use it like this :
In Program.cs, you can see :
Application.Run(new Form1());
So, I create a new form, call it SplashScreen.
In that form I create a timer, for example 3s.
In event splashScreen_Load, I start the timer.
After 3s, I get an event timer_Tick.
In that event, I close the form.
So, change the line in Program.cs to :
Application.Run(new SplashScreen()); // will show for 3s, then closed
Application.Run(new Form1()); // after that, Form1 will show.
|
|
|
|
|
First add a form and name it as splashForm and then on that form remove the border and place a picture box which contains a suitable image.
Include using system.thread;
now in the main form(Form1)
public Form1()
{
thread = new Thread(new ThreadStart(SplashForm));
thread.Start();
}
private void SplashForm()
{
SplashForm newSplashForm = new SplashForm();
newSplashForm.ShowDialog();
newSplashForm.Dispose();
}
private void Form1_Load(object sender, EventArgs e)
{
thread.Abort();
}
I hope this helps you...
|
|
|
|
|
Thanks A zillion evry one !!! its done
|
|
|
|