Note that there are some explanatory texts on larger screens.

plurals
  1. POBubble-Sort with 2D Array
    text
    copied!<p>Howdy, I do know how to implement a simple bubble-sort for 1dimensional array. But with 2dimensional or multidimensional, that's where I have my problems.</p> <p>So far I've been using this to sort 1Dimensional Arrays, works like a charm. But mostly with integer numbers, not strings:</p> <pre><code>boolean sort; do{ sort = true; for (int i = 0; i &lt; testarray.length - 1; i++){ if(testarray[i] &gt; testarray[i+1]){ temp = testarray[i]; testarray[i] = testarray[i+1]; testarray[i+1] = temp; sort = false; } } }while(!sort); // Descending Output // for (int k = testarray.length - 1; k &gt;= 0 ; k--){ // Ascending Output for (int k = 0; k &lt; testarray.length ; k++){ System.out.print(testarray[k] + ", "); } </code></pre> <p>Assuming I have:</p> <p>Customernumber, Name, Surname, Address</p> <pre><code>String customers[][] = {{"123", "John", "Doe", "Somewhere"}, {"007", "James", "Bond", "MI5"}, {"1337", "Lolcat", "Izgud", "Saturn"}} </code></pre> <p>Now, I want to choose to sort what to sort after: customernumber, name, surname or address. And after that I want to output it ascending or descending, depending what I want.</p> <p>I just have no idea how to implement this with bubble-sort. I want to stay in bubble-sort, , no other sorting algorithm, I want to learn how bubble-sort works in such a situation.</p> <p>For ascending and descending my idea would be: I could do an if-Loop. For example <code>if (asc == 1) then output ascending, else output descending</code>. The asc would then be asked via Console for example.</p> <p>Any help is much appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload