×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    47

    how to INSERT data in an ARRAY in ARBITRARY order??

    Dear all

    I want to declare an array with 3000 elements, ,and then add data to the array in arbitrary order

    I have tried the following

    CArrayPtrFlat<CResData)* iArray;
    iArray = new (ELeave) CArrayPtrFlat<CResData> (3000);

    then i tried to use a for loop to add data

    *************************************
    for(TInt i=0; i<size; i++) // size is supposed to be smaller than 3K
    {
    id = GetId();
    iArray->InsertL(id, data);
    }
    *************************************

    I know that InsertL cannot perform what i want because i cannot insert to a position GREATER than the number of elements in the array

    So how to achieve the arbbitrary insertion??

    thx a lot

  2. #2
    Super Contributor
    Join Date
    Apr 2003
    Location
    Czech Republic
    Posts
    915
    AppendL() doesn't work for you?

  3. #3
    Super Contributor
    Join Date
    Apr 2003
    Location
    Czech Republic
    Posts
    915
    oops, I was too quick, I see it now..:-)
    Cannot you sort the elements before you start to adding them into the array?

  4. #4
    Nokia Developer Expert
    Join Date
    Apr 2003
    Location
    Finland
    Posts
    425
    Hello, I have used this kind arrays for sorting:

    Code:
    RPointerArray<CResData> iArray;
    
    // Returns positive value,
    // if aLeft object has creater position, negative value if aRight
    // object has creater position, and zero if positions are equal.
    static TInt CResData::CompareItemPositions (const CResData& aLeft,const CResData& aRight)
    {
        return aLeft.iDesiredPosition - aRight.iDesiredPosition;
    }
    
    
    TLinearOrder<CResData> key CResData::CompareItemPositions);
    
    CResData* item = CResData::NewL(position);
    item->iDesiredPosition = 666;
    User::LeaveIfError(iArray.InsertInOrderAllowRepeats (item,key));
    
    // Now item is in place '1' but it will be in place 666 when there is all 3k items are added.
    Br V.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •