Actionscript 3 ActionScript3中有deque吗

Actionscript 3 ActionScript3中有deque吗,actionscript-3,deque,Actionscript 3,Deque,我想一种方法来存储多达三个字符串。当我得到一个新的时,我想将它添加到列表的底部,并从列表的顶部删除它(最旧的一个) 我知道这可以在python中用deque实现,但不确定如何在AS3中实现,或者它是否已经存在。google搜索在googlecode上找到了一些代码,但没有编译。我想一个合适的解决方案是使用数组存储字符串,然后使用pop和unshift删除和添加项目 e、 g 我认为一个合适的解决方案是使用数组来存储字符串,然后使用pop和unshift来删除和添加项目 e、 g 可以将字符串存储

我想一种方法来存储多达三个字符串。当我得到一个新的时,我想将它添加到列表的底部,并从列表的顶部删除它(最旧的一个)


我知道这可以在python中用deque实现,但不确定如何在AS3中实现,或者它是否已经存在。google搜索在googlecode上找到了一些代码,但没有编译。

我想一个合适的解决方案是使用数组存储字符串,然后使用pop和unshift删除和添加项目

e、 g


我认为一个合适的解决方案是使用数组来存储字符串,然后使用pop和unshift来删除和添加项目

e、 g


可以将字符串存储在或中

大堆 -将一个或多个元素添加到数组的开头,并返回数组的新长度。数组中的其他元素从其原始位置i移动到i+1

-从数组中删除最后一个元素并返回该元素的值

var arr: Array = [ "three", "four", "five" ];

arr.unshift( "two" ); 
trace( arr );   // "two", "three", "four", "five"

arr.unshift( "one" ); 
trace( arr );    // "one , ""two", "three", "four", "five"

arr.pop(); //Removes the last element 
trace( arr );   // "one , ""two", "three", "four"
因此,在你的情况下:

“我想将它添加到列表的底部,并从列表的顶部删除它(最旧的一个)。”

数组中有3个字符串,您可以按如下方式访问它们:

trace( arr[0] );  //first element
trace( arr[1] );  //second element
trace( arr[2] );  //third element
矢量 因为您只想存储字符串,所以可以使用它来获得更好的性能

Vector类简言之是一个“类型化数组”,具有与array类似的方法

您的情况的唯一区别在于声明:

var vect: Vector.<String> = new <String>[ "my", "three", "strings" ];

vect.unshift( "newString" );  //add it to the bottom of the list

vect.pop(); // remove the one from the top of the list 
var-vect:Vector.=新的[“我的”,“三个”,“字符串];
向量取消移位(“新闻字符串”)//将其添加到列表的底部
vect.pop();//从列表顶部删除该项

您可以将字符串存储在或中

大堆 -将一个或多个元素添加到数组的开头,并返回数组的新长度。数组中的其他元素从其原始位置i移动到i+1

-从数组中删除最后一个元素并返回该元素的值

var arr: Array = [ "three", "four", "five" ];

arr.unshift( "two" ); 
trace( arr );   // "two", "three", "four", "five"

arr.unshift( "one" ); 
trace( arr );    // "one , ""two", "three", "four", "five"

arr.pop(); //Removes the last element 
trace( arr );   // "one , ""two", "three", "four"
因此,在你的情况下:

“我想将它添加到列表的底部,并从列表的顶部删除它(最旧的一个)。”

数组中有3个字符串,您可以按如下方式访问它们:

trace( arr[0] );  //first element
trace( arr[1] );  //second element
trace( arr[2] );  //third element
矢量 因为您只想存储字符串,所以可以使用它来获得更好的性能

Vector类简言之是一个“类型化数组”,具有与array类似的方法

您的情况的唯一区别在于声明:

var vect: Vector.<String> = new <String>[ "my", "three", "strings" ];

vect.unshift( "newString" );  //add it to the bottom of the list

vect.pop(); // remove the one from the top of the list 
var-vect:Vector.=新的[“我的”,“三个”,“字符串];
向量取消移位(“新闻字符串”)//将其添加到列表的底部
vect.pop();//从列表顶部删除该项

push()将元素添加到数组的末尾,而不是前面。oops!我的错。谢谢你指出这一点。我已经编辑了我的文章,以便更正错误。push()将元素添加到数组的末尾,而不是前面。oops!我的错。谢谢你指出这一点。我已经编辑了我的帖子,使事情变得正确。