2011-02-11 393 views

回答

11

http://www.sgi.com/tech/stl/next_permutation.html

线性。最多(最后 - 第一)/ 2 掉期。

要查看源代码,只需查看系统的STL头文件即可。在类似Unix的系统上,您可能需要寻找类似/usr/include/c++/4.1.2/bits/stl_algo.h的地方。

+3

实际上,它比线性好。这是摊销O(1) - 即,如果你叫它n!次,它只需要O(n!)操作,而不是n * n !.见[这个问题](http://stackoverflow.com/questions/4973077/the-amortized-complexity-of-stdnext-permutation)。 – ShreevatsaR 2011-06-30 11:58:30

相关问题