/ Published in: ActionScript 3
Looking forward for the most optimized solution for the same
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> <mx:Script> <![CDATA[ // second highest element in an array public var arr:Array = new Array("1", "2", "3", "4", "5", "6", "7","8"); // ("2", "1", "4", "3", "6", "5", "8", "7"); public var swapArr:Array = new Array(); public function init():void{ for(var i=0;i<arr.length;i++) { txt.text += "\n hi " +i; var a = arr[i]; var b = arr[i+1]; a = a^b; b = a^b; a = a^b; txt.text += "\n "+a+" ???? "+b; swapArr.push(a); swapArr.push(b); if(i<arr.length){ i++; } } for(var k=0;k<swapArr.length;k++){ txt.text += "\n "+swapArr[k]; } } ]]> </mx:Script> <mx:TextArea x="118" y="57" width="553" height="412" id="txt"/> </mx:Application>