2011-02-11 180 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

相關問題