Created
May 5, 2014 23:15
-
-
Save nadako/64addeb08e4a87907dbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Reverse.reverse; | |
class Main | |
{ | |
static function main() | |
{ | |
var a = [1,2,3]; | |
for (v in reverse(a)) | |
{ | |
trace(v); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Main.main = function() { | |
var a = [1,2,3]; | |
var _g_array = a; | |
var _g_length = a.length; | |
while(_g_length > 0) { | |
var v = _g_array[--_g_length]; | |
console.log(v); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Reverse<T> | |
{ | |
var array:Array<T>; | |
var length:Int; | |
inline function new(array:Array<T>) | |
{ | |
this.array = array; | |
this.length = array.length; | |
} | |
public inline function hasNext():Bool | |
{ | |
return length > 0; | |
} | |
public inline function next():T | |
{ | |
return array[--length]; | |
} | |
public static inline function reverse<T>(array:Array<T>):Reverse<T> | |
{ | |
return new Reverse(array); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment