Built-in sort with Arrays.sort

I have multidimensional array that contains a number as new arr int [10] [10] and that you want to sort according to the last column. Arrays.sort is a simple way to do it, but what happens if I don't want a real movement elements occur by Arrays.sort (arr [] []). Frankly, I'm interested in winning positions but not to grant the lines. Can I pass it arrange step because not interested in changing the original table? For the moment, I sort the table with Arrays.sort then index of table row and I fixed the position number pair. For example arr [0] has rank 1, arr [1] has the rank of 2 etc. If sorted according to the last column.

Published by: totalnewby on May 23, 2011 22:51

totalnewby wrote:
I just need to know where the items would be positioned if they have been sorted. I made copy of the table at the moment and my program is successful, even if it takes a lot of time and additional memory to perform the copy because this table has billions lines in reality. If you can suggest less time-consuming solution do let me know.

This is my standard example of how to do this sort of indirect.

 public static void main(String[] args) throws Exception
    {
        final Words words = new Words("/usr/share/dict/words");
        final List data = new ArrayList();
        for (int i = 0; i < 10000; i++)
        {
            String[] row = new String[10];
            for (int j = 0; j < row.length; j++)
            {
                row[j] = words.getRandomWord();
            }
            data.add(row);
        }

        final Integer[] indirectIndex = new Integer[data.size()];
        for (int i = 0; i < indirectIndex.length; i++)
        {
            indirectIndex[i] = i;
        }

        final Comparator indexComparator = new Comparator()
        {
            @Override
            public int compare(Integer left, Integer right)
            {
                int result = 0;
                for (int i = 0; result == 0 && i < data.get(left).length; i++)
                {
                    result = data.get(left).compareTo(data.get(right)[i]);}return result;}};

Arrays.sort(indirectIndex, indexComparator);

for (int i = 0; i < 100; i++){System.out.println(indirectIndex[i] + "\t" + Arrays.toString(data.get(indirectIndex[i])));}}

You just need to create a Comparator for sorting the index array that uses the last entry in each row of real data array when comparing a row rather than all the row entries as I have done. 

Tags: Java

Similar Questions

  • Wizard built in form with Validation issues

    APEX 4.2.4, running with the Wizard built in form, with a collection as a source of data from a table. I have a manual process to save the data in my table, but I have a couple of columns having validation Wizard built on them.  When I try and save I get the message annoying that it means my data are tool and I need to update my table...

    I thought that this could be due to having disabled on my form, or perhaps because of the unalterable columns columns...  However, when I went and built a manual validation routine (have look through the g_f00x table storing data from columns one) I was still able to get this annoying message "Outdated information" to appear...

    Does anyone have a reliable solution when using forms in a table to get rid of this message?

    (Previous conversations showed my group here how to remove the "Save before paging message", then perhaps another similar solution there...)

    Thank you

    Tony Miller

    Ruckersville, WILL

    Tony Hey,

    Only point fcud table?

    You can just run

    $("input[name=fcud]").val("C");
    $("input[name=fcs]").val("");
    

    No need to use. each(). I have not really a configuration with a form of hybrid tab on a collection at hand to test, but I think that just those of compensation and submission should not produce these errors. I could be wrong however. Try to start with debugging to see if you can spot something?

  • Unexpected result with Array.sort

    There seems to be a problem with the sort function when sorting the table contains several elements that are equal. I tried to illustrate this in the most simple form below:

    var test1:Array = ['a', 'b', 'this,' would be '];

    var test2:Array = [', 'c', 'b', 'a'];

    var test3:Array = ['a', 'b', 'c', ' a'];

    var test4:Array = ['a', ' a ',' b ', 'a'];

    trace (test1.sort (Array.RETURNINDEXEDARRAY)); Should be 0,1,2,3 (well!)

    trace (test2.sort (Array.RETURNINDEXEDARRAY)); Should be 3,2,1,0 (good!)

    trace (test3.sort (Array.RETURNINDEXEDARRAY)); Must be 0,2,3,1 (evil)

    trace (test4.sort (Array.RETURNINDEXEDARRAY)); Must be 0,1,3,2 (evil)

    / * Output

    0,1,2,3

    3,2,1,0

    3,0,1,2

    3,1,0,2

    */

    Can anyone find a reason of incompatibility, or is this a bug in the sorting method?

    test3: must be 0,3,1,2 or 3,0,1,2.  They are the same.

    test4: 0,1,3,2 is the same as 3,1,0,2 is the same as 1,0,3,2 is the same as 0,3,1,2 etc.  That is to say, as long as the index 2 is the last, they still.

    Oh, I see the problem.  you think flash is assign an index to the elements of the original array.

    It is not the case.  the method released the list of indices in the sort order.  IE, 0,3,1,2 means the original elements of 0th and 3rd tables are first and 2nd and the 1st element is the third and the 2nd element is the last.

    so, if you wanted to list the elements of original paintings using your sort order for test3, for example, you would use:

    test3 [0], test3 [3], test3 [1], test3 [2] and you expect, a, b, c

  • How parallellize a loop with arrays?

    Hello

    Trying to improve the performance of a program I want to parallellize a loop. This loop uses a vi that returns an array, and I guess it can be of different lengths to each iteration. The current solution is a classic CONCATENATE via shift register parallellization impossible paintings, but there should be a work around, right?

    /Y

    Hi Yamaeda,

    When you concat elements in an array in a loop, you need a registry to offset either by BuildArray or ReplaceArraySubset (with a predefined table)...

    A possible workaround: when your Subvi bays differ in length, place them in a cluster. So you can use autoindexing to build a cluster of the table - with the disadvantage of needing another loop to concatenate the subtables later...

    Is this useful?

  • Array of integers with array of bool

    I have an array of integers large read in a worksheet. All ones and zeros.

    The table is 200 000 length and width 10-bit words. I need to convert to an array of Boolean in order to

    create a chart of digital waveforms. I can convert it using loops, but it will take more than an hour.

    Is there a quick way to convert an array of 200 000 x 10 of integers (ints) to an array of bool?

    This should be much faster than the curls.  I was not looking for it with a great picture.

    Lynn

  • A little help with arrays

    Hi guyz

    I have a problem with the reading and processing of element of an array. I have a "reference database generator" and for example I generate a sine wave. Can I use 'Get waveform components' to get the data for the chart, after that, I have a table 1 d of data (right?) at the exit of the "component of the waveform to Get' block.» I need to read everything, treat it and then send it as a value from a function entry. So, how can I get all the elements in this array and send it further?

    I hope that I was clear with my problem.

    It would be great if you could provide me with assistance.

    Thank you very much

    Andrei_L.

    And just for completeness:

  • DLL of LabVIEW with arrays of strings in c ++

    I'm looking to use labview to retrieve a list of gas to a txt file and then transfer this list to gas in a C++ program.

    I thought it would be easier to just list the gas transfer a string array of the DLLs in labview to my C++ program.  However, I am not able to output the list of gas using tables; I am only able to output the pointer, not the chain that makes reference to the needle.  Of course, I have a syntactic problem with my method of output.

    I have no problem out of the list of gas via a simple string.  However, the approach of single string requires multiple calls to the relevant dll.

    My code is based on the labview dll for C++ routines example titled call of Labview DLL in Visual C++ this Passes table manages in reference (http://zone.ni.com/devzone/cda/epd/p/id/1518).

    I am sure that what I'm trying to make is simple enough for an experienced programmer to Labview.  However, my labview, C/C++ and experience is limited.

    Thank you in advance for your help.

    My labview and C code is found in the attached zip file.  However, the basic C code and output resulting are:

    // Call DLL.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "Array_Multiply.h" #include  #include  #include  #include  #include  using namespace std; int main(int argc, char* argv[]) { TD1Hdl handle_var3; long temp; char stringout[25]; temp=25; handle_var3 = (TD1**)DSNewHandle(sizeof(TD1)); // initialize sizes (*handle_var3)->dimSize = 1; // // Gasstring is a function that outputs a Labview array of strings. // However, I can't make this work. All I am doing is outputting // memory addresses. // Gasstring(&handle_var3); cout << "\n gasstring " << *handle_var3; cout << "\n gasstring " << handle_var3; cout << "\n gasstring " << (*handle_var3)->String[0]; //cout << "\n gasstring " << (*handle_var4)->Numeric[0]); // // Gasstring3 is just a single string. There are no issues outputting // this string. // Gasstring3(stringout,temp); cout << "\n gasstring3 " << stringout; cout << " \n enter in number "; cin >> temp ; return 0; }
    

    The output of my source code is:

    I think I understood something :-)

    cost < "\n="" gasstring ="" "=""> < lstrbuf(*(*handle_var3)-=""> String [0]);

    There are some macros useful for LStrHandles in "extcode.h", LStrBuf is one of them.

    It seems that there are no problems with memory management, you did it right.

  • Variable with Array Manager

    When I use a table as a shared variable, how can I view the entire table with the Variable-Manager?

    I see only the first element of the array, but none of the following.

    I'm using LabVIEW 8.2 however.

    Thanks in advance

    You can just display the first item, there is no other way in the variable Manager.

    Christian

  • How can I use an itemrenderer with array of actionscript?

    I am eager to fill a list control with multiple Checkbox controls, I understand how to use the itemrenderer, but all the examples I found complete the table outside the actionscript dataprovider, I want to know how to create my table inside action script and switch to the list box. When I was playing with this I could get listbox to populate with box, but not so it would be the label of the elements, I think that I don't pick the right information in the table.

    Change your code as shown below, and it works. Use an instead of a one line external rendering engine.


    http://ns.Adobe.com/MXML/2009.
    xmlns:s = "library://ns.adobe.com/flex/spark".
    xmlns:MX = "library://ns.adobe.com/flex/mx".
    creationComplete = "init ()" > "
       
           
       

       
       
            Import mx.collections.ArrayList;
    public var myarray:ArrayList;
    public var returnedarray:Array = ['a', 'b', 'c', ', 'e', 'f', 'g', 'h'];
    public var key: String = "label".
    public void init (): void {}
    myArray = new ArrayList();
    for (var i: int = 0; i<=(returnedarray.length-1);>
    var myobj:Object = {};
    myObj [key] is [i] returnedarray m:System.NET.SocketAddress.ToString ();.
    myarray.addItem (myobj);
    }
    FileList.dataProvider = myarray;
    }
    ]]>
       

       
       
       
       
           
       

    then create "myItemRenderer" in the same folder...


    http://ns.Adobe.com/MXML/2009.
    xmlns:s = "library://ns.adobe.com/flex/spark".
    xmlns:MX = "library://ns.adobe.com/flex/mx".
    autoDrawBackground = "true" >
       
       

    I hope it's what you expected.

    Kind regards

    Select this option.

  • Can I send a request for 'Built' to someone with new material and operate without having to load any software? It is application DAQmx.

    I've finished, work application LabVIEW 7.1.  It is built as an executable file.  If I have a long distance user buy the necessary materials, my exe file will recognize the front end and work?

    Ron

    You should be able to create an installer that automatically includes all the needed to run your application.

    MAX configuration exported

    LabVIEW Run-Time

    DAQmx Run-Time

    MAX

  • Update of digital control with different values with array function

    Hello

    I have attached my code base. I want to execute the code for 2 sets of digital control with a gap between the two values, then pass it. Something like that

    ABC

    Initialize the P1 = 10; P2 = 20; P3 = 30; P4 = 40

    Run the code

    delay = 10ms

    Update of P1 = 150; P2 = 200; P3 = 350; P4 = 500

    Run the code

    jump to abc

    I am stuck how can I update the values of P1, P2, P3, P4? I thought about using a function table but couldn't go further.

    Thanks for the help,

    Ana

    Hello Ana,

    One way you might achieve what you are looking for is using property nodes. These property nodes will allow you to change the values of the block diagram control. You can set up a structure of case inside your loop that will change control through nodes of property value after a certain number of iterations. Here is a community sample that shows how to use the nodes property to change the Boolean controls:

    https://decibel.NI.com/content/docs/doc-22669

    -Erik S

  • Can I use a godaddy domain name once I built my site with muse cc?

    I'll use the Muse CC to build my site, can use a dad bought domain name go to my site, wether I host by adobe or not? (what is the best option for this?)

    See you soon

    Hello

    Yes, you can, you can either host your website with Godaddy or Adobe Business catalyst. in both cases, you will be able to use your domain name that you purchased at Godaddy.

    Let us know if you have any other questions.

  • Pre-built virtual machine with OBIEE and APEX

    Hi all

    I searched for a virtual machine with OBIEE and APEX pre-installed, but I can't find it... or information messages on this subject. Does anyone know if y at - it a selection of pre-designed developer programs VM with these two tools?
    I currently have the "database App Development VM' with APEX in there, but I can't understand how to install OBIEE inside.

    Any help will be appreciated.

    Please, if this is not the right category where I should ask the question, let me know and I'll move it.

    Thank you.
    Elena.

    PL see deployment guide in the link above - the model of computer virtual includes version of database 11.2.0.3, which should be the APEX installed by default in it. If this isn't the case, it will be much easier to install the APEX in the VM OBIEE.

    For sharing files between the host and the guest, pl see the Virtualbox documentation - http://www.virtualbox.org/manual/ch04.html#sharedfolders

    HTH
    Srini

  • CS5 built and deployed with "Disable AAM."  How to enable updates without having to reinstall?

    I used Adobe Enterprise Deployment Manager to create a package Design Premium CS5.  Now 6 users who have received this package report that they cannot update their own facilities.  I realized that a default build configuration has the box checked ' disable the MAO"!

    In the package build itself, there is a file called "optionxml.xml" that contains a line about updates, with a "remove = true" indicator is defined.  This seems to be only configurable during compile.

    Is it possible to change this on customers, once it is deployed, without having to reinstall the suite?

    Adobe has a TechNote to disable the AAM, the procedure might work in reverse, that is, to find and delete/rename AdobeUpdaterAdminPrefs.dat. See http://kb2.adobe.com/cps/850/cpsid_85016.html for more details

    The computer-wide disability

    To disable access to updates for all users on a given computer, administrators can create an admin preferences file. (This file disables access to updates both the help > menu updates, as well as automatic update of controls.) Create a text file named AdobeUpdaterAdminPrefs.dat with the following content:

    
    
         
    
         1
    
         
    

    Place the file in the following location:

    Mac OS / Library/Application Support/Adobe/AAMUpdaterInventory/1.0/AdobeUpdaterAdminPrefs.dat
    Windows XP and above C:\Program Files\Fichiers files\adobe\AAMUpdaterInventory\1.0\AdobeUpdaterAdminPrefs.dat
    Windows XP and higher (64-bit) C:\Program files (x 86) \common files\adobe\AAMUpdaterInventory\1.0\AdobeUpdaterAdminPrefs.dat

    Note: This will also prevent administrators to check updates and installation of updates through this verification of updates. This situation is easily dealt with by simply renaming the file AdobeUpdaterAdminPrefs.dat, run the update checking and installation with Adobe Application Manager, and then restore the file to its original name.

  • How to subtract array with arrays of each element index

    Please help me, I have some problem in my programs of VI, how to subtract (B1 - B1), (B1 - B2), (B1 - B3) and etc. in block diagram labview? I tried to use the index table, but in my data 10 x 120, I do not have of course the program execution will be inoperative. can someone help me to solve it? Thank you.

    Hi bimoo,

    How to subtract (B1 - B1), (B1 - B2), (B1 - B3) and etc. in block diagram labview?

    Like this:

Maybe you are looking for

  • A lot of pop-up windows and sticking in the browser behavior

    Have weird ads via safari and chrome. A lot of popup displays in any browser and also a few become clickable buttons disabled and typing becomes almost impossible through any program that uses the web. When you are not running any browser, everything

  • OKR: The restoration of EXTERNAL drive?

    I have beautifully OKR working for me. However, when I choose "System Recovery", it only show up with selecting in C: or D: (partitions on the drive HARD internal only). It won't let me choose backups that she herself created on my external USB HDD (

  • Why do I need to install the SP63801 update?

    HP Pavilion dv7, Windows 7, 64-bit, which is about a month. Someone can explain to me in layman's term what is this update and why do I need the WinFlash utility updated to locally Flash the system BIOS (ROM)? (I don't even know what it means, I just

  • laptop HP envy 15 (progression of the volume bar)

    When I rush the incr or decr for her I see a progress bar that went from 1 to 100 now, it no longer appears can I get it back

  • Computer is unstable to the multiple problems on Windows Vista

    Original title: failover my laptop is very unstable, how never juice I install norton anti virus and uniblue registry booster but I have still problems... I'm 2 Impossible to enter in my Start menu... sometimes I can't even find the start menu button