Sort an array with two fields

i have an array with three fields: id, name and date.
i want to sort it by name first and then date.
the size of my array could be as large as 1 million.
what could be the most efficient way to do so?
tia!

It's very inefficient to sort an array on "the fly".
In that case at least use a linked list so you don't
have to move all elements after the insertion point to
make room for a new insert. But it's much better to
sort afterwards when all elements are in the array.Use a TreeSet. A linked list will be slower than a TreeSet, I suspect.
I believe that with a TreeSet, insertions will be somewhat slower (O(logN) vs O(c)), but the subsequent sorting of a linked list will be, what, at least O(NlogN) and possibly O(N^2)? And when you're inserting the first elements into the TreeSet, it should be closer to O(c) anyway, whereas the after-the-fact sorting of a LinkedList wouldn't have an advantage like that.
Then if necessary extract an array out of the TreeSet when you're done creating/inserting elements.
But really, use a database.

Similar Messages

  • Adding a custom tab in Purchase Order with two fields - ME21N

    Hello Experts,
    My requirement is to add a custom tab with two fields in purchase order at header level.
    The BADI ME_PROCESS_PO_CUST is alreday implemented previously as there was one custom tab added previously in header.
    The structure  CI_EKKODB already have the custom fields for the enhancement done earlier.
    Now to add my additional tab how should i proceed ....should i put my additional fields in the same structure and write my code in same BADI.....will there be any impact on already done enhanecement.
    Please suggest in achieving this functionality.
    Thanks,
    Naveen

    Hi,
    Check this [wiki|http://wiki.sdn.sap.com/wiki/display/ABAP/DetailedexplanationaboutBADIandthewaystofindtheBADIwithanexample%28ME23n+transaction%29], it tells you how to do with an example for item data.
    Regards,
    Eduardo

  • Generic delta   using function module with two fields  AEDAT AND ERDAT

    Hi,
        i have scenario that i have to create a generic data source  having delta using funcation module and the delta speci fields are AEDAT AND ERDAT . Is there possibility with out using these two fields ( i mean AEDAT AND ERDAT)  in the extract structure can i create the data source . and provide sample code for me . it is very urgent.
    waiting for the reply,
    sri.c

    Hi Sri,
    here some coding, I hope this helps!
    first, get the delta-field
          LOOP AT s_s_if-t_select INTO l_s_select.
            CASE l_s_select-fieldnm.
              WHEN 'ZDATE'.
                MOVE-CORRESPONDING l_s_select TO r_date.
                IF r_date-high IS INITIAL OR r_date-high = space.
                  r_date-high = '9991231'.
                ENDIF.
                APPEND r_date.
            ENDCASE.
          ENDLOOP.
    Cursor öffnen
          OPEN CURSOR WITH HOLD s_cursor FOR
          SELECT * FROM
          WHERE  ....
          AND    erdat in r_date
          AND    aedat IN r_date.
          FETCH NEXT CURSOR s_cursor INTO CORRESPONDING FIELDS OF table e_t_data package size s_s_if-maxsize.
    regards
    Siggi
    PS: Note that this coding only works for a very straight forward extraction.
    Message was edited by: Siegfried Szameitat

  • Use DISTINCT with two fields to return one record

    I am using OleDB with a SELECT DISTINCT query that is used in C# code to populate a DataGridViewComboBox.  The queried table has two fields: ID and Description. The ID field values are unique. Descriptions may be duplicated. The DataSource of my DataGridViewComboBox
    is ListBoxItems which is a ListBox that is populated from a table. The ValueMember is ID and the DisplayMember is Description.  A sample table might look like this:
    ID    Description
     1     Blue
     2     Blue
     3     Red
     4     Blue
    I want my query to return two records; one for the Red description and only one for the Blue description.  I don't care which Blue description it returns, but I do need the corresponding ID for the selected Blue record and the ID value for the Red record. 
    Using SELECT DISTINCT ID, Description FROM... would give me four records instead of two.  How can I return only two records in this scenario?
    Rob E.

    Using window function:
    create table #temp
    ID int,
    description varchar(20),
    insert into #temp Values(1,'blue')
    insert into #temp Values(2,'blue')
    insert into #temp Values(3,'red')
    insert into #temp Values(4,'blue')
    ;WITH CTE AS (select RN=ROW_NUMBER() OVER (PARTITION BY description ORDER BY newid() ),
    ID,description from #temp)
    SELECT ID, description from CTE
    WHERE RN = 1;
    ID description
    4 blue
    3 red
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • Generic Delta with Two fields

    Hi,
    Can it be possible to have Delta on two fields in Generic Data Source?
    If yes, Please let me know the Procedure.
    Thanks,
    Ram.

    hi,
      generic data source is nothing but if u used one data source to upload the data to one  ods. at that time u want the same data source for next cube also.that time u crete the generic data source and create transformation ods to cube and also create the dtp ,upload the data.
    delta means its filter the same records present in next time.
    1.create data source and infopackage.
    2.upload the data to datasource(psa).
    3.create ods.
    4.create transformation.(use that data source).
    5.create dtp.
    6.execute the data.
    7.create cube.
    8.right click the ods.
    9.create generic data source.
    10.right click the ods create transformation(use torget as cube)
    11.create dtp.
    12. that will have full or delta updates .
    13. use delta update.
    14.execute the data.
    if its helpfull assign points.
    thanks.
    prakasu

  • Using member sorting and grouping with two reports sharing rows

    Hi!
    I have a problem with one report and I need some help or advise here.
    I have two dimensions with dynamic expansion in rows (PRODUCT, MATERIAL), and I use the option Member Sorting and Grouping at Member selector to obtain the total amount of PRODUCT group by PARENTH1:
    PRODUCT               MATERIAL          AMOUNT
    TOTAL PROD_A-X                                   100
    PROD_A_A             MAT1                          22
    PROD_A_B             MAT1                          50
    PROD_A_A             MAT2                          28 
    TOTAL PROD_B-X                                   120
    PROD_B_A             MAT1                          30
    PROD_B_A             MAT2                          50
    PROD_B_B             MAT2                          40
    This works fine if I only have one report, but I need to create another one sharing the row and page axis with the Default Report, when I do that the option Member Sorting and Grouping doesn't work. I really need to have two reports with shared rows and also the summation by PARENTH1, how can I do that?
    Thank you very much

    Hi!
    I have a problem with one report and I need some help or advise here.
    I have two dimensions with dynamic expansion in rows (PRODUCT, MATERIAL), and I use the option Member Sorting and Grouping at Member selector to obtain the total amount of PRODUCT group by PARENTH1:
    PRODUCT               MATERIAL          AMOUNT
    TOTAL PROD_A-X                                   100
    PROD_A_A             MAT1                          22
    PROD_A_B             MAT1                          50
    PROD_A_A             MAT2                          28 
    TOTAL PROD_B-X                                   120
    PROD_B_A             MAT1                          30
    PROD_B_A             MAT2                          50
    PROD_B_B             MAT2                          40
    This works fine if I only have one report, but I need to create another one sharing the row and page axis with the Default Report, when I do that the option Member Sorting and Grouping doesn't work. I really need to have two reports with shared rows and also the summation by PARENTH1, how can I do that?
    Thank you very much

  • Query activities with two fields having OR condition

    I am building a module in c# and I need to query all activities that were (created in last 60 days OR that got completed in last 60 days). If this is possible can anyone show me how?

    Add two instances of Activity1 to your ListOfActivity array on the input of the query. The filter on the first one should be "created in last 60 days". The filter on the second one should be "created before 60 days ago AND completed in last 60 days". Make sure that both elements in the ListOfActivity array have the same fields populated.

  • Sorting an Array using two variables

    Hi,
    I has an ArrayList of objects that have two variables that need to be used to sort the ArrayList.
    Sorting using one variable is fine, but how do I sort once using both variables?
    any ideas would be great
    tks
    Phill

    I have to do this a lot, so I came up with a more reusable solution. I have two Compatator classes, one that permits me to compare two objects based upon a bean property value. Another lets me chain two Comparator objects together. So I create two of the bean comparators and chain them together. Similar code exists in the Jakarta Commons Lang project.

  • Sort a table with two columns based on the first

    I have a powershell table with the columns 'Used Perc' and 'ID'.
    This was formed from the following 
    $a = @{Expression={[System.Math]::Round(($_.nUsed_Avg/$_.nSize)*100,1)};Label="Used Perc";width=25}, @{Expression={$_.nStatisticalDiskIdentificationID};Label="ID";width=15}
    $GLOBAL:CSV2 = Import-CSV $STATDISKOUT | Format-Table $a
    Before this, the file $STATDISKOUT had the columns 'nUsed_Avg', 'nSize', and 'nStatisticalIdentificationID'.
    My question is, how would I sort the new table based on 'Used Perc' but keeping the corresponding 'ID' column lined up to the right value?

    We use a select statement to reorder columns and recalculate,  The formatters just go at the end to adjust the display.
    Import-Csv <file> | select <column order format> | Format-Table
    or you can do it in the table:
    Import-Csv <file | Format-Table -Properties ,f1.,f2.,,f3....Here is how to inset a sort inline:
    $a=@{
    L='ID';
    E={$_.nStatisticalDiskIdentificationID};
    L='Used Perc';
    E={[System.Math]::Round(($_.nUsed_Avg/$_.nSize)*100,1)}
    Import-CSV $STATDISKOUT | Select $a | Sort 'Used Perc' | Format-Table -Auto
    ¯\_(ツ)_/¯

  • Howto select all entries with two fields value

    Hi all,
    I have the following SELECT stmt:
          SELECT SUM( betrw )
            INTO l_real_t
            FROM dfkkop
           WHERE opbel = l_opbel
             AND hvorg <> gc_hvorg_dun_fee
             AND tvorg <> gc_tvorg_dun_fee.
    Now I get no lines, where hvorg = gc_hvorg_dun_fee OR tvorg = gc_tvorg_dun_fee.
    But my intention is to get no lines, where BOTH conditions are met.
    What am I doing wrong here?
    Kind Regards, Matthias

    Check this..
    SELECT SUM( betrw )
            INTO l_real_t
            FROM dfkkop
           WHERE opbel = l_opbel
             AND NOT ( hvorg EQ gc_hvorg_dun_fee
             AND tvorg EQ gc_tvorg_dun_fee).

  • Sort array with equal elements

    Hi, I'm a new one.
    I have a problem to sort 2d array with equal elements (it has 5000000 of elements from 1-255) for example:
    1 2 1 1 3 4 5 5 6 1 2 3 (value from 1-255)
    2 2 1 1 3 3 3 3 4 4 4 1 (value from 1-255)
    And I need make array or matrix 255 rows vs 255 colomns, and count how many equal elements for example:
      1  2 3 4 5 6
    1 0 1 0 1 0 0
    2 0 1 0 1 0 0
    3 1 0 1 0 0 0 
    4 0 0 1 0 0 0
    5 0 0 2 0 0 0
    6 0 0 0 1 0 0
    I'll be happy if someone could help me

    I understand that it's very complicated explain.
    I build 2d array from two 1darray each of them has values 1-255. So right now i must constract array or matrix 255x255 where must calculat how many times value from (1-255) for one array in another array and write this sum for each value 1-255. I try to show it
    1 2                         so I need array 3x3; for first row for value 1 I have two times value 3 and one time value 2
    2 2                                                                                    2 I have two times value 1 and one time value 2 and one time value 3
    3 2                                                                                    3 I have two times value 2 and one time value 3 
    3 2              so my result matrix will be      1   2  3
    3 3                                                       1  0  1  2
    2 3                                                       2  2  1  1
    2 1                                                       3  0  2  3
    2 1
    1 3
    1 3
    Maybe its more clear

  • Sorting an array of numbers with loops

    Hi, i'm looking for a way to sort an array or numbers with loops.
    my array looks like this. int[] numbers = {5,2,7,9,1}
    i know how to use the "sort" method and i want to do it without the sort method, but i am not very clear on the logic behind it.
    by the end it should look like this, {1,2,5,7,9}
    i know 2 loops are used, can you please give me a logic to work with.
    i have started the loops but what to do inside???
    int temp;
    for (int i=0; i<numbers.length; i++){
    for (int j=1; j<numbers; j++){
    if (numbers<numbers[j])
    temp = numbers[i];
    Any suggestions i will be thankful for.
    thank you.

    fly wrote:
    no not really a homework question.. i want to improve my logic because it is very poor at the moment.. but i'm sure someone knows how to sort an array with loops only.Yes, we do know how to do it, I once wrote a heapsort in assembly code, as a real work project. But you rarely get a project like that the good ones were all done years ago.
    All the algorithms I suggested you look at use loops. the simplest and slowest is the bubble sort. This one runs by comparing values and swapping their locations, the wikipedia article http://en.wikipedia.org/wiki/Bubble_sort has the algorithm.

  • Sorting table combine with Assending n DESCENDING  value

    Dear All ...
    i want to sort by table  with some field.  which some of the field in assending  n some in desending.
    example: this my table itab .
                 1.1.09       a            H 
                 1.1.09       c            H
                 1.1.09       c           S
                 1.1.09       a           S
    after sort  become
               1.1.09       a          S   
               1.1.09       a          H   
               1.1.09       c          S   
               1.1.09       c         H   
    from above sample ....... 1st n 2nd value is sort in assending , but 3th sort in desending ....
    any idea ?

    Hi,
    Try this,
    DATA: BEGIN OF itab OCCURS 0,
            f1(15) TYPE c,
            f2(15) TYPE c,
            f3(15) TYPE c,
          END OF itab.
    itab-f1 = 1.
    itab-f2 = 'a'.
    itab-f3 = 'H'.
    APPEND itab.
    itab-f1 = 1.
    itab-f2 = 'c'.
    itab-f3 = 'H'.
    APPEND itab.
    itab-f1 = 1.
    itab-f2 = 'c'.
    itab-f3 = 'S'.
    APPEND itab.
    itab-f1 = 1.
    itab-f2 = 'a'.
    itab-f3 = 'S'.
    APPEND itab.
    SORT itab by f1 f2 f3 DESCENDING.
    LOOP AT itab.
      WRITE:/ itab-f1, itab-f2, itab-f3.
    ENDLOOP.

  • RAID 1 Issue - One array becomes two

    All:
    I have setup a RAID 1 array with two identical segate SATA 150 drives.  This was a clean install, and everything went without a hitch.  My problem is this: after a week or so, I would boot the PC and The BIOS RAID array would say "Error--Degraded."  It took a long time to boot, but was fine and when I got into Windows, my C:\ drive was joined by a D:\drive (the second Seagate.)
    I shut down, rebooted, and went into the RAID BIOS.  The second drive had magically gained its own array (non-bootable), which I deleted.  The PC booted fine with a healthy RAID array, and all was well. 
    Until it happened again a day later.  And again.  And again.  Basically, the array doesn't stay stable for more than a couple days.  I even swapped out the drives with Seagate as they were clicking.  The new ones are good, but the problem still occurs.
    I have not experienced any data loss, but am mystified as to what is going on here...Any help would be greatly appreciated!
    Thank You,
    Michael Tschirret
    MSI K8N Neo2 Platinum Edition v 1.40
    Athlon 64 3200+
    1 GB DDR 2700 SDRAM (2 512MB sticks)
    2 HDD 160GB|Seagate Barracuda 7200.7 Sata 150
    1 WD 100GB External IDE hard drive
    Sony CD-R/RW DVD +/- R/RW
    TDK CD-R/RW
    1 Floppy drive
    SB Audigy 2 ZS Platinum
    eVGA GeForce 6800GT

    I'm having the same problem, except I am using 4 hdds in RAID 0+1. one drive dropped out and the machine crawls now. Could it be an issue with SATAI vs SATAII? I have 4 Seagate Barracuda 120GB drives, but they were purchased over a two year period, so I suspect their firmwares vary a bit...
    Any help would be much appreciated.
    BTW, I have the latest BIOS installed (v1.B)

  • One RAID Array Becomes Two???

    All:
    I have setup a RAID 1 array with two identical segate SATA 150 drives.  This was a clean install, and everything went without a hitch.  My problem is this: after a week or so, I would boot the PC and The BIOS RAID array would say "Error--Degraded."  It took a long time to boot, but was fine and when I got into Windows, my C:\ drive was joined by a D:\drive (the second Seagate.)
    I shut down, rebooted, and went into the RAID BIOS.  The second drive had magically gained its own array (non-bootable), which I deleted.  The PC booted fine with a healthy RAID array, and all was well.
    Until it happened again a day later.  And again.  And again.  Basically, the array doesn't stay stable for more than a couple days.  I even swapped out the drives with Seagate as they were clicking.  The new ones are good, but the problem still occurs.
    I have not experienced any data loss, but am mystified as to what is going on here...Any help would be greatly appreciated!
    Thank You,
    Michael Tschirret
    MSI K8N Neo2 Platinum Edition v 1.40
    Athlon 64 3200+
    1 GB DDR 2700 SDRAM (2 512MB sticks)
    2 HDD 160GB|Seagate Barracuda 7200.7 Sata 150
    1 WD 100GB External IDE hard drive
    Sony CD-R/RW DVD +/- R/RW
    TDK CD-R/RW
    1 Floppy drive
    SB Audigy 2 ZS Platinum
    eVGA GeForce 6800GT

    I'm having the same problem, except I am using 4 hdds in RAID 0+1. one drive dropped out and the machine crawls now. Could it be an issue with SATAI vs SATAII? I have 4 Seagate Barracuda 120GB drives, but they were purchased over a two year period, so I suspect their firmwares vary a bit...
    Any help would be much appreciated.
    BTW, I have the latest BIOS installed (v1.B)

Maybe you are looking for

  • Ssh operation time out

    In my office, I have a MacBook and a Mac Pro. I tried to ssh to the Mac Pro from the Macbook and got the "operation time out" error. I am able to ssh to a Linux box from my Macbook. Anybody has encountered this? Thanks.

  • Strain measurment and write to file with NI9237

    Hopefully this lab view VI can help some of the novices like myself to acquire strain using the NI9237 and write to a file.  The example VI available from NI "Cont Acq Strain Samples (with calibration)" is fine for sampling data and viewing on a char

  • How can I found out which swf is loaded?

    I need to write an if statement for my menu to find out which swf is loaded into a certain level. On my menu, I have code that when a user clicks on a button, it reloads a new swf over itself into the same level. I have the menu in a shared library,

  • Updated to OSX Maverick and now I can't stream shows from DirectTV.

    I recently updated my macbook pro to OSX Maverick and now I can't stream shows from DirectTV.

  • Bookmarks window missing

    There are a lot of features in Mavericks I am trying to change back or find alternatioves to, I am hoping there is someone here who can help me out. The old bookmarks window is gone in Safari.  I used it to view whole groups of URLs and now that it i