java - Bubble-Sort with 2D Array -
How do I know how to implement a simple bubble-sort for the 1dimensional array? But with 2dimensional or multi-dimensional, this is where I have my problems.
So far, I'm using it to sort 1 dimensional array, works like a magic but with no integer numbers, no string:
Boolean sort; Do {sort = true; For (int i = 0; i & lt; testarray.length - 1; i ++) {if (testera ray [i]> testarray [i + 1]) {temp = testarray [i]; Testress [I] = TestRayer [I + 1]; Testrace [I + 1] = temporary; Sort = false; }}} While (sort!); // for coordinates output // (int k = testarray.length - 1; k> = 0; k -) {// for ascending output (int k = 0; k & lt; testarray.length; k ++) {system .out.print (testera ray [k] + ","); Assume that I have: custom name, name, surname, address
string client [] [] = { {"123", "John", "Do", "Somewhere"}, {"007", "James", "Bond", "MI5"}, {"1337", "Lockcat", "Egguent" "Saturn"}}
Now, I want to choose the option of Sorting: Customer Number, Name, Tuneem or Address. And after that I want to ascend or descend it, which depends on my wish.
I do not know that bubble-sort I want to be in bubble-sort, no other sorting algorithm, I want to know how bubble-sorting works in such a situation.
My thoughts will be for ascending or descending: I am a -Loop For example if (ACC == 1) then output is ascending, other output descending
. For example, AOCs will be asked through the console.
Any help is greatly appreciated.
A2 dimensional array is basically just a 1 dimensional array that contains the array.
Only use code that, instead of just your entourage, move the inner arrays.
To know if an array is next to 'big', compare the string values of the correct array member (hence the name or surname, ..) To do this you use the String Comparison method can do.
Final Note: The example you provided is better if the internal array is actually an information object
For example:
class person { Int customerNumber; For example, you can databotype different areas for all fields. String name; String Sur Noam; String address; }; Edit: To really answer your question:
Change your program to the following:
Make a temporary announcement Change:
string [] temp;
and change the row:
if (testress [i]> testera ray [i + 1])
In:
if (testress [i] [1]> testaray [i + 1] [1])
with name Work and sort on
R
Comments
Post a Comment