Sort both arrays

Hi all

If we are given two berries sorting, X and Y and X has a big enough buffer at the end of stay there.

How can merge us Y X in a sorted order.

X = (1,4,7,8)

Y = (2,5,6)

output: 1,2,4,5,6,7,8

Thank you

Rambeau

This is a table... so a table is a construction that has a number of elements.

The presentation of an array is can be done like this:

SELECT listagg (COLUMN_VALUE, ',') WITHIN GROUP (ORDER BY COLUMN_VALUE)

IN my_string

table (z);

sys.dbms_output.put_line (my_string);

HTH

Tags: Database

Similar Questions

  • Sorting algorithm: How can I sort both arrays according to a

    I have two rows parallel, similar to this:

    var array1 = [4, 3, 1, 5, 2];

    var Array2 is ['four', 'three', 'one', 'two', 'five'];.

    I want to sort the first table and the second table followed the same kind as the first. Any advice for a good algorithm would be appreciated.

    Rick Quatro

    This gives a try!

    var array1 = [4, 3, 1, 5, 2];
    var array2 = ["four", "three", "one", "five", "two"];
    
    bubbleSort(array1,array2);
    
    function bubbleSort(a,b)
    {
        var swapped;
        do {
            swapped = false;
            for (var i=0; i < a.length-1; i++) {
                if (a[i] > a[i+1])
                {
                    var temp = a[i];
                    a[i] = a[i+1];
                    a[i+1] = temp;
    
                    var temp = b[i];
                    b[i] = b[i+1];
                    b[i+1] = temp;
                    swapped = true;
                }
            }
        } while (swapped);
    }
    
    alert(array1);
    alert(array2);
    
  • Sort groupItems Array using the left coordinate of visible limits?

    Hey all! It's been a while, but I'm back with some more busters of brain for you guys.

    I'm trying to re - work a script that Silly-V wrote to me. The goal is to create a work plan around each group of a document element in the order of the top left corner to the lower right (as if reading a book). (ultimately I would like to add a provision that excludes the possibility of having a work plan contained by another work plan, but it is a luxury that I can try to find later).

    Silly script works very well and does exactly what I need... about 60% of the time. The problem comes when I have an item that contains a clipping mask. Since work plans are created through groupItem.visibleBounds, Illustrator assumes that the invisible work that extends beyond the clipping mask is visible and creating a work plan that is too much.

    His version pushes the visible boundaries of each groupItem in an array, then sorts the visible boundaries of the left coordinate, then pushes this sub-table in another table and at the end, to coordinate kinds berries vertically at the top... However, I'm looking to push the real groupItems in the table instead of just the visible limits. So I would like to sort the groupItems by their visible limits table and then I have the opportunity of either by creating work plans based on their visible limits or (the possibility of) loop to make each groupItem selected = true and using the fitArtboardToSelectedart() command.

    I'm stuck on how to sort the groupItems table based on the visible limits... Here's what I have so far:

    my inclination is to set a variable to the visibleBounds of each groupItem in temp (which seems like it would need a loop), but it's not supposed loop me XIRR...? There is something really big, I'm missing here, but I can't wrap my head around it.

    Thanks for any help!

    function organize(){
      var docRef = app.activeDocument;
      var layer = docRef.layers[0];
      var groups = layer.groupItems;
      var currentRowMarker;
    
      var groupList = []; //array of all groupItems
      var sortedGroupList = []; //array of subarrays sorted by visible bounds
      var temp = []; //temporary array for the current row of groupItems. sort this array from left to right first, then push the entire array into "sortedGroupList"
    
    
      //populate groupList
    
    
      for (g=0; g<groups.length; g++){
           groupList.push(groups[g]);
      }
    
    
      //set currentRowMarker and compare rest of groupList to top coordinate of visible bounds. push true results to temp array.
    
    
      for (t=0; t<groupList.length; t++){
      temp = [];
      currentRowMarker = groupList[t].visibleBounds[1];
      temp.push(groupList[t]);
      groupList.splice(t,1);
    
           for (c=0; c<groupList.length; c++){
                var currentGroup = groupList[c];
                var vB = groupList[c].visibleBounds[1];
                     if (vB + 20 > currentRowMarker && vB - 20 < currentRowMarker){
                          temp.push(currentGroup);
                          groupList.splice(c,1);
                     }
           }
    
      //this is where i'd like to sort the temp array
    
      sortedGroupList.push(temp);
      }
    }
    organize();
    

    Thanks for your help, Vassili.

    I've been unable to get your suggestion to work, does not mean that it was an erroneous suggestion. So I decided to go the more complicated route. I hope that I can learn about why your suggestion did not work for me in a subsequent attempt.

    I am sure that this isn't the most elegant way to perform this task, but it was the only way that makes sense to me. Here's what I ended up with:

    for (s=temp.length; s>0; s--){
      var placeholder = 0;
      var farthestLeft;
      var deleteIndex;
           for (a=0; a		   
  • to sort an array of numbers NOT as strings using the. sort()

    Hello

    y at - it a function or a simple way to sort an array of numbers in the order of their values and not as strings? For example, 100 came AFTER 9; (9, 100) (100, 9).

    Thank you.

    Use the ARRAY.numeric parameter.

    (and you can still use a custom for kinds more custom sort function parameter).

  • Sorting multiple arrays at different indexes

    I have just another very quick question on tables, this time on the sort of them. I just re-wrote my code to use for correspondence with values of 2 tables and then adding them to the screen.

    However, it seems that my correspondent is far away, it matches the items that are the same index, which is not always the case

    The output for the matches, which should be next to sideis as follows (which is incorrect), so I'll try to find values to levels different index

    Dunlop
    Babolat
    Wilson
    Wilson
    Head
    Dunlop
    Adidas
    head
    Babolat
    Slazenger
    Slazeger
    Prince
    Prince
    Völkl
    Völkl
    Adidas

    I tried to sort the array, but it seems that the table cannot be sorted as I want. I simply wanted to do ascending sort, but change to lowecase wouldn't do what I had to do.

    This is the code, the matchInfo function should do all the work

    package {
         
         import flash.display.*;
         import fl.transitions.*;
         import fl.transitions.easing.*;
         import flash.net.*;
         import flash.events.*;
         import flash.text.*;
         import flash.text.AntiAliasType;
         import bucket_left;
         
         
         public class CustomClass extends MovieClip {
              
              //Position Variable
              private var position:uint;
              
              //XML responsible variables 
              private var xmlLoader:URLLoader;
              private var xmlContainer:XML;
              private var xmlList:XMLList;
              
              //Array specific variables 
              private var rackUSA:Array;
              private var rackOther:Array;
              private var imagesArray:Array;
              
              
              //This is the constructor of the application 
              public function CustomClass() {
                   position = 50;
                   rackUSA = new Array();
                   rackOther = new Array();
                   imagesArray =  new Array();
                   LoadXML();
              }
              
              private function LoadXML() {
                   xmlLoader = new URLLoader();
                   xmlLoader.load(new URLRequest("http://localhost/xml/index.php"));
                   xmlLoader.addEventListener(Event.COMPLETE, populateInfo);
              }
              
              public function populateImages(imgname:String, imgurl:String) {
                   var imageLoader:Loader = new Loader();
                   imgname = imgname.split(".gif").join("");
                   imageLoader.name = imgname;
                   imagesArray.push(imageLoader);
                          imageLoader.load(new URLRequest(imgurl));
              }
              
              public function matchInfo(infoArray:Array, imagesArray:Array) {
                   infoArray.sort();
                   trace(infoArray);
                   for (var c:uint = 0; c < imagesArray.length; c++) {
                        trace(infoArray[c].brand);
                        trace(imagesArray[c].name);
                        if (infoArray[c].brand.toLowerCase() == imagesArray[c].name) {
                             var brand:TextField   = new TextField();
                             var country:TextField = new TextField();
                             var made:TextField    = new TextField();
                             var cost:TextField    = new TextField();
                             var bucket                  = new bucket_left();
                             brand.text   = infoArray[c].brand;
                             country.text = infoArray[c].country;
                             made.text    = infoArray[c].made;
                             cost.text    = infoArray[c].cost;
                             
                             //Align Data
                             bucket.y = position;
                             bucket.x = 100;
                             brand.x = -50;
                             brand.y = -35;
                             country.x  = -45;
                             country.y  = -10; 
                             made.x = -45;
                             made.y = 5;
                             cost.x = 45;
                             cost.y = -10;
                             imagesArray[c].x = -100;
                             imagesArray[c].y = -35;
                             
                             addChildAt(bucket, 0);
                             bucket.addChild(DisplayObject(imagesArray[c]));
                             bucket.addChild(brand);
                             bucket.addChild(country);
                             bucket.addChild(made);
                             bucket.addChild(cost);
                        }
                        position += 150;
                   }
              }
              
              private function populateInfo(event:Event) {
                   
                   //Incoming XML Data
                   xmlContainer = new XML(event.target.data);
                   xmlList = xmlContainer.product;
                   //
                   
                   //Variables to hold the string
                   var brandTxt:String;
                   var country:String;
                   var material:String;
                   var price:String;
                   var image:String;
                   
                   for (var i:uint = 0; i < xmlList.length(); i++) {     
                   if (xmlList.country.text()[i] == "USA") {
                   brandTxt = xmlList.brand.text()[i];
                   country = "product of " + xmlList.country.text()[i];
                   material = "made of " + xmlList.material.text()[i];
                   price = "$" + xmlList.price.text()[i];
                   image = xmlList.image.text()[i];
                   rackUSA.push({brand: brandTxt, country: country, made: material, cost: price, pic: image});
                   } else if (xmlList.country.text()[i] == "Other") {
                   brandTxt = xmlList.brand.text()[i];
                   country = "product of " + xmlList.country.text()[i];
                   material = "made of " + xmlList.material.text()[i];
                   price = "$" + xmlList.price.text()[i];
                   image = xmlList.image.text()[i];
                   rackOther.push({brand: brandTxt, country: country, made: material, cost: price, pic: image});
                   }
                   populateImages(image, "http://localhost/rackets/" + image);
                   }
                   matchInfo(rackUSA.concat(rackOther), imagesArray);
              }
         }
    }
    

    given an element of imagesArray the following function returns the first object in infoArray where the brand property corresponds to the element:

    function infoArrayF(ldr:Loader):Object {}

    for (var i: uint = 0; i<>

    {if (infoArray [i]. Brand.toLowerCase () is LDR. Name)}

    return infoArray [i];

    }

    }

    }

    //

    and you can use this function as follows:

    var obj:Object = infoArrayF (imagesArray [c]);

    If you want just the hint of infoArray returned from infoArrayF, I return instead of infoArray [i]

  • The order of the points in a sort pathPoints array

    Well, why would I do that? Well, I have areaText the rectangles that have been created by various means, and index 0 is sometimes high on the left, other times the bottom right. I need to do a lot of resizing, alignment, spacing, sizing. To describe the movement of the top left point of each (or anywhere else), I'm trying to clean up the sequence of points in each table pathPoints objects in order to move the pathPoint [0] .anchor for each rectangle and make sure that the upper left corner moves, not another random corner.

    Then, test only one script, and I came up with the following (don't laugh about how I called the table), which works very well in extendScript:

    var testArray = new Array;

    testArray.push ({xVal: 5,:0}) yVal;})

    testArray.push ({xVal: 0, yVal:-2});

    testArray.push ({xVal: 5, yVal:-2});

    testArray.push ({xVal: 0, yVal:0});})

    function primarySort() { testArray.sort (function (a, b) {return b.yVal - a.yVal});}   }

    function secondarySort() {}

    reorganize the first pair of xVal-based points

    If (Number(testArray[0].xVal) > Number(testArray[1].xVal)) {}

    Sensors = testArray [1];

    testArray.splice (1,1);

    testArray.unshift (moveMe) ;}

    reorganize the second pair of points based on xVal

    If (Number(testArray[2].xVal) < Number(testArray[3].xVal)) {}

    Sensors = testArray [2];

    testArray.splice (2.1);

    testArray.push (moveMe) ;}    }

    function printArray() {}

    for (i = 0; i < testArray.length; i ++) {}

    var writeMe is testArray [i].xVal.toString () + ', ' + testArray [i].yVal.toString ();.

    $.writeln (writeMe);  }}


    primarySort();

    printArray();

    $.writeln ('... ») ;

    secondarySort();

    printArray();

    So then I tried to do the same thing for Illustrator:

    var ObjArr = app.activeDocument.textFrames;

    var objPoints = new Array;

    for (i = 0; i < objArray.length; i ++) {}

    var pathObj = .textPath ObjArr [i];

    objPoints = pathObj.pathPoints;

    XYpairSort() ;}

    function XYpairSort() {}

    writes the current sequence of anchor pathPoint y coordinate x in the console

    for (i = 0; i < objPoints.length; i ++) {}

    writeMe var = objPoints [i] .anchor [0] m:System.NET.SocketAddress.ToString () + ', ' + objPoints [i] .anchor [1] m:System.NET.SocketAddress.ToString () + "," + i;

    $.writeln (writeMe) ;}

    Sort the four points at the top and at the bottom of the pairs

    objPoints.sort (function (a, b) {return b.anchor [1]-a.anchor [1]});

    reorganize the first pair of xVal-based points

    If (Number(objPoints[0].anchor[0]) > Number(objPoints[1].anchor[0])) {}

    Sensors = objPoints [1];

    objPoints.splice (1,1);

    objPoints.unshift (moveMe) ;}

    reorganize the second pair of points based on xVal

    If (Number(objPoints[2].anchor[0]) < Number(objPoints[3].anchor[0])) {}

    Sensors = objPoints [2];

    objPoints.splice (2.1);

    objPoints.push (moveMe) ;}

    writing the new sequence of pathPoint anchor y coordinate x in the console

    for (i = 0; i < objPoints.length; i ++) {}

    writeMe var = objPoints [i] .anchor [0] m:System.NET.SocketAddress.ToString () + ', ' + objPoints [i] .anchor [1] m:System.NET.SocketAddress.ToString () + "," + i;

    $.writeln (writeMe) ;}

    }

    Who raises an error "objPoints.sort is not a function".

    Unlike the single version JS, my script HERE trying to sort all the points of all of the textAreas, which I will fix shortly so it sorts the 4 points for each object. The problem is that the script is not sorting points, but providing a helpful error instead.

    Any ideas? Research on the Internet for this error does not explain why it happens, just in other ways to do the kinds.

    Well, if you did this time to the discussion, the approach I took is completely unnecessary.

    You see, I knew .top, .the .width and .height rectangles properties, and if you changed the width of a textFrame, he would scale the text that it contains:

    var obj = app.activeDocument.textFrames [0] / / guess that's narrower than the 2 inches

    obj. Width = 144; will scale the width of the block and its content also.

    Thus, to avoid the problem of scaling that I had to make sure that the textPaths of what I had selected was the same index order for I can enter each item individually and always take the same point for each textFrame. I was changing the height and width of each textFrame by assigning new XY coordinates at each angle of the trajectory. Good to know how to do this, but not necessary, because the attributes .top, .the, .width and .height are available for the textPath object.

    What I do not know (and do now), is that you can change the path without scaling the content:

    var obj = app.activeDocument.textFrames [0] / / guess that's narrower than the 2 inches

    var objPath = obj.textPath;

    objPath.width = 144;  is not at the scale of the text inside the frame.

  • 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. 
    
  • easier way to sort the array of strings 2D?

    I have an array of strings long 2d, and I would like to sort by the value 2. It originated as:
        public static final String names[][] = {
         {"000000", "Black"},
         {"000080", "Navy Blue"},
         {"0000C8", "Dark Blue"},
         {"0000FF", "Blue"},
            {"000741", "Stratos"},
            ...
         {"FFFFF0", "Ivory"},
         {"FFFFFF", "White"}
        };
    As you can see, they are first sorted by hexadecimal values. It is useful for the part of the application.

    There are 1 567 entries. I want to the alphabetize the names of color and place them in a widget from the list. I need to retain the values to hexadecimal color associated with name values. All I can think to do something like:

    (1) to a temporary array of strings of length 1 - d
    2) fill loop that adds hexadecimal values in the values of name: temp [i] = new String (names [1] + names [i] [0])
    (3) sort [temporary] with built in the sort of Java
    (4) make a permanent new string, [hexValues] array to hexadecimal values
    (5) copy the last 6 characters of each item to [hexValues]
    (6) to truncate the last 6 characters of each element in [temporary]
    (7) create widget with [temporary] list

    Is there a more elegant way? What I really want to do is build an array of int 1 d, with the values that represent locations in alphabetical order of the names. However, I see no integrated whole that would make this kind of indirect type.

    - - - - - - - - - -
    Second question - can the bottom of each item in a list widget be a different color? Ideally, the list would display in black or white color name and its value of color as the background. Specifically, I am trying to build the list produced by the JavaScript here:

    * http://chir.ag/projects/name-that-color/

    and add it to my Java interactive color wheel:

    * http://r0k.us/graphics/SIHwheel.html

    - - - - - - - - - -
    BTW, I've converted its name this Javascript (ntc.js) color to a native Java class. It is freely distributable, and I have the host here:

    * http://r0k.us/source/ntc.java

    -Rich

    Published by: RichF October 7, 2010 19:04
    Stupid forum software; I don't see what he did go italic the new Word.

    People forget that a 2D array is essentially a table 1 d of paintings.

    colorNames.add(new colorName(ntc.names[1], ntc.names[0]));
    

    The above code attempts to pass arrays as parameters to your Builder, but your Builder expects a String object.

  • GPO sorting FlexField array elements is possible?

    Hi all.

    I have a table, this table contains more than one column, one of them is FlexField, which contain 7 columns.  Case in common, I put the column real SortAllowed property and it will work, but it does not work with FlexField. How can I fix this (if itn is possible)?

    I don't have a lot of time.

    Nice day.http://www.otmfaq.com/forums/images/smilies/tongue.png

    p.s Flex field has property Type: Descriprive.

    Hi Alex,

    Because Oracle does not sort on DFF, you can check if you need the FDF itself values (in function of the importance is the requirement of sorting). A solution could be to capture the columns in FACT as of the independent columns of the database in the custom table and allow to sort. But this way you'd lose the flexitbities provided by DFF.

    Concerning

  • PHP - sort an array in order descending

    Hello

    In PHP, I create the HTML table below.  I want to sort by the vote of $effective value in descending order.  How do I do that?

    Thank you

    John

    If (mysql_num_rows ($result) > 0) {}
    {while ($table = mysql_fetch_row ($result))}
    Print "< class p =-"topic\"> $table [0] < /p > \n";
    $r = mysql_query ("SELECT * FROM ' $table [0]'");


    print ' < table class =-"navbar\" > \n ";
    {while ($Row = mysql_fetch_array ($r))}

    $effective_vote = $row ["votes_up"] - $row ["votes_down"];

    Print "< tr >";

    print "< td >". ["' < a href ="http://'.$row['site'].' ' class = 'links2' > '. $row ['site']. '< /a >'. "< table > '; '.
    print '< class td = 'votes' > '. "< span class ="votes_count"id ="votes_count"." $row ['id'].' ' > '.number_format ($effective_vote). "</span > '. "< table > ';
    print '< class td 'ballot box' = > '. "< span class ="button"id =" button '. "" $row ['id'].' ' > '. "< a href =" "javascript:;" class = "cell1" id = "". " $row ['id'].' ' > '. Vote. "< /a > '. "</span > '. "< table > ';
    }
    Print "< /tr > \n";
    }
    Print "< /table > \n";

    SELECT  * , votes_up - votes_down AS effective_vote
    FROM  `$table[0]`
    ORDER  BY effective_vote DESC
    

    This also gives you $row ["effective_vote"] as part of your database result.

  • Array.sort() compare strangeness function in ExtendScript

    I write this in InDesign Scripting forum, because I met the problem while he was working on a script for InDesign CC 2015, but it seems to cover all of ExtendScript.

    In my script, I use the method array.sort() with a custom comparison function to sort an array of objects with respect to one of their properties. I will introduce a version widespread in the party so that it is easier to analyze and reproduce.

    var myArray = [{
        name: "A",
        size: 20
    }, {
        name: "B",
        size: 10
    }, {
        name: "C",
        size: 30
    }, {
        name: "D",
        size: 30
    }];
    
    myArray.sort(
        function(a, b) {
            if (a.size > b.size) {
                return 1;
            }
            if (b.size > a.size) {
                return -1;
            }
            return 0;
        });
    
    
    var names = [];
    for (var i = 0; i <= myArray.length - 1; i++) {
        names.push(myArray[i].name)
    };
    names;
    

    The expected result is "B, A, C, D. B must go before A, as its size is smaller than A, while C and D should remain unchanged, because their size is equal.

    However, the result provided by ExtendScript is "B, A, D, C. For some reason, C and D become reversed.

    I believe that the source of this behavior lies with incorrect treatment of ExtendScript part returns 0 .

    To confirm that, I replaced the triage function with

    myArray.sort(
        function(a, b) {
            return 0;
        });
    

    which, according to my understanding of how the comparison functions are supposed to work, must return the entire unchanged table (regardless of the entry). But in this case ExtendScript treats as "B, C, D, A.

    I would be very grateful if someone could confirm if it is indeed a bug (or at least a dull implementation of the ECMAScript standard). Or is everything works as it should and the error on my part?

    Advice as workaround for this problem would also be very useful. Thank you!

    Thanks for that suggestion!

    Your answer made me read on different algorithms sort and their implementation in the different JavaScript engines. Apparently, ExtendScript uses what is called an unstable sorting algorithm, which is precisely the cause of a non desired behavior with values of the sort condition.

    To implement a different and stable algorithm (for example, merge sort) in your script is certainly an option, but it seemed overkill for my purposes.

    Fortunately, I was able to find another solution.

    First, add a property 'position' for each element of the array, based on its current position. For example:

    for (i = 0; i < myArray.length; i++) myArray[i].position = i;
    

    Then, simply change the latest state of the sort function so that it compares the position of each element:

    myArray.sort(function(a, b) {
        if (a.size > b.size) {
            return 1;
        }
        if (b.size > a.size) {
            return -1;
        }
        if (a.size == b.size) {
            return a.position - b.position;
        }
    });
    

    I hope this will be useful to those who might encounter the problem in the future.

  • Array.sort is unstable?

    Use Array.sort, when the compareFunction always retrun 0, it will change the order of the elements in array. (in javascript, is not)

    is the quick sorting using Array.sort, which is unstable?

    and how to fix it not change the order of the elements.

    Thanks for any help.

    Here's the test code:

    Student.As

    package
    {
              public class Student
              {
                        public function Student(name:String, age:int)
                        {
                                  this.name = name;
                                  this.age = age;
                        }
      
                        public var age:int;
      
                        public var name:String;
      
                        public function toString():String
                        {
                                  return "[name=" + name + " age=" + age + "]";
                        }
              }
    }
    
    

    Applicatoin.MXML

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                                            creationComplete="application1_creationCompleteHandler(event)">
              <mx:Script>
                        <![CDATA[
                                  import mx.events.FlexEvent;
      
                                  private var ac:Array = [
                                            new Student("ST1", 21),
                                            new Student("ST2", 21),
                                            new Student("ST3", 21),
                                            new Student("ST4", 21)
                                  ];
      
                                  protected function application1_creationCompleteHandler(event:FlexEvent):void
                                  {
                                            ac.sort(function(a:Object, b:Object):int
                                            {
                                                      if (a.age > b.age)
                                                                return 1;
                                                      else if (a.age < b.age)
                                                                return -1;
                                                      return 0;
                                            });
                                            trace(ac);
                                  }
      
                        ]]>
              </mx:Script>
      
    </mx:Application>
    
    

    the result is:

    [name=ST3 age=21],[name=ST2 age=21],[name=ST1 age=21],[name=ST4 age=21]
    

    Array.sort has change the order of the elements in array

    See http://stackoverflow.com/questions/3026281/array-sort-sorting-stability-in-different-brows ers

    Array.sort is not necessary to be stable according to ECMA.  Looks like the recent browsers have implemented a stable sort, but Flash does not.

    AS3Commons claims to have a stable sort.  See http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/ actionscript/org/as3commons/collections/utils/ArrayUtils.as

  • Arrays.sort

    Why did the Arrays.sort method defined as

    public static sort (Object [] a) Sub

    Instead of

    public static sorting Sub (comparable [] a)?

    user9987428 wrote:

    jverd wrote:
    In this way we can sort an array whose elements are all mutually comparable, even if the table itself is not declared as being of a Comparable type. I can't think of a specific use case where it would be useful, but that's the only reason why I can think for deliberately to make that decision.

    Dear jverd, I'm not sure that the case you are referring. I tried the following code and it gives a runtime Exception.

    The current implementation does not allow it and even though I was thinking exactly the same thing as jverd suggested, I think it is more likely that it's just an oversight.

  • BUG: 1 D table sort isn't sorting table of Classes and table Clusters contain Classes

    the function "sort the table 1 d.

    I wanted to sort the array of Clusters [number and class]. But to my surprise, LV is not like him.

    Okay, I need sort table Classes. But maybe once in the future I will. :-)

    'Research in table 1 d' is the use of classes I do not understand why 'sort the table 1 d' does not work.

    This problem is in LabVIEW 8.2 and 8.5 2009

    I think that the search feature of table 1 d can address each element in the table as an agregate whereas sort requires access to the private data in the data from the class and carrying it even further...

    Say all the elements are in the Parent class and a tow children who both have private data that are uniqie each and not present in the class of parents...

    How they manage breaking when there are different fields to sort on?

    Ben

  • Sort a table of strings [problem]

    Well, im pretty new in the java development and app, I used to make games using AS3 and now I am with my teacher in certain BlackBerry applications.

    The thing is I can't sort an array of string, I looked around and I noticed that I need to make a comparison.

    I want to sort an array of XML that will be used on a drop-down list. How can a comparator and use it?

    Easy PS:go on me, im really new ^^

    Which part of this is a problem with? Looks like things fairly straigh-forward.

    You write a class that implements the comparison. You have two methods to implement, compare() and equals(). Each method is passed two objects. It is the responsibility of your application to prvide the good performance based on the two objects.

    Since your comparator compares strings, you have already integrated routines to compare.

    String.compareTo)

    and

    String.Equals)

    In both cases, you can simply return the value of the construction compared with chains.

    See the javadocs for comparator, String, and SimpleSortingVector

    Work on it a bit and come back with a more specific question.

Maybe you are looking for

  • ITunes lock with Get Info

    I just convert a good majority of my DVD collection to mp4 (m4v) and the addition of my library in iTunes (under the general rubric of the videos/movies.  The films are located on an external drive that is connected directly to the computer Mac Pro r

  • iOS question 9.3

    On my iPhone 6 anymore, since the upgrade to iOS 9.3 my Safari browser crashes / hangs on all the other sites that I try to interact with! Everyone knows about this problem? I'm beyond frustrated at this point fightlong my desire to do a frisbee! If

  • Flow 11: Use as extra 'hard drive' SD card on a HP stream

    I want to use a 64GB SD card for additional storage. It seems that I can't leave the SD card in place when I stopped because the stream is not "see" the SD card on the re-start unless I have to remove and reinsert the card. I am doing something wrong

  • How can I reinstall Windows Defender on my laptop HP Vista 64-bit?

    Bots and a kind of virus/hacker got in and everything moving & ripped off many drivers needed for important security programs such as defender and Trend Micro Titanium, Ran Malwarebytes and Spy - bot Search & Destroy, but nothing came.  Responsible f

  • Cisco VPN Client and Windows XP VPN Client IPSec to ASA

    I configured ASA for IPSec VPN via Cisco VPN Client and XP VPN client communications. I can connect successfully with Cisco VPN Client, but I get an error when connecting with the XP client. Debugging said "misconfigured groups and transport/tunnelin