Results 1 to 9 of 9

Thread: Arrange Array;

  1. #1
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default Arrange Array;

    So, could someone give me a hand creating a function to rearrange an array?

    Here is what I mean:

    Array := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

    The output would be something like

    Array := [5, 6, 7, 8, 9, 0, 1, 2, 3, 4];

    So, it keeps the order, but just moves a certain index to the front, and continues the array.

    ANY HELP WILL BE APPRECIATED!

    Thanks;
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  2. #2
    Join Date
    Dec 2007
    Location
    Somewhere in Idaho
    Posts
    480
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    so.. You want two arrays, one that sorts the other, right? (So array 1 points to each element in array two in sorted order)

  3. #3
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Well, not sure about that way, but look at the BubbleSort and QuickSort procedures
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  4. #4
    Join Date
    Jun 2006
    Location
    United Kingdom
    Posts
    116
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    program New;

    function ReArray(Arr: array of Integer; StartingIndex: Integer): array of Integer;
    var
      i: Integer;
    begin
      SetLength(Result, Length(Arr));
      for i := StartingIndex to High(Arr) do
        Result[i-StartingIndex] := Arr[i];
      for i := 0 to StartingIndex-1 do
        Result[High(Arr)-StartIngIndex+i+1] := Arr[i]
    end;

    var
      Arr, Arr2: array of Integer;
      i: Integer;

    begin
      Arr := [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20];
      Arr2 := ReArray(Arr, 5);
      for i := 0 to Length(Arr2)-1 do
        Writeln(IntToStr(Arr2[i]));
    end.

  5. #5
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    I recommend using Swap().



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  6. #6
    Join Date
    Jul 2007
    Location
    Ottawa, Canada
    Posts
    930
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Or you could just look up QuickSort in delphi, and then modify it to your use... kindof like wizzup did in his plugin

    @Wizzup busted

    oh wait... ur going backwards.. wow...

    that totally ruined my busting wizzup moment *smacks self* yea do what wizup said...

    for i := 0 to whatever do
    begin
    swap(array[0], array[randomrange(1, high(array))]);
    end;
    ~ Metagen

  7. #7
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Meta, I busted him. You, are just a noob.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  8. #8
    Join Date
    Jul 2007
    Location
    Ottawa, Canada
    Posts
    930
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nooo, u sent me the data, and i noticed the similiarities I totally busted him!!

    (only because i happened to find the same algorithm and i tampered with it the exact same way wizzy did to fix YOUR function)
    ~ Metagen

  9. #9
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Daniel, thanks. I'm using that currently. Wizzy, how would you use swap?
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Array in an array...
    By Lorax in forum OSR Advanced Scripting Tutorials
    Replies: 20
    Last Post: 01-16-2010, 09:10 PM
  2. ItemColors: Array of Array of Integer
    By n3ss3s in forum Research & Development Lounge
    Replies: 5
    Last Post: 10-30-2007, 06:04 PM
  3. Array of Tbox - And TPoint array helps.
    By R0b0t1 in forum OSR Help
    Replies: 4
    Last Post: 06-10-2007, 06:43 PM

Posting Permissions

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