Permutations of a list using stack
<p>I'm trying to find a way to enumerate all combinations of a list of numbers without recursion or using itertools.  I came up with a solution that works but I think it turned into a recursive function after all.  I'm new to Python and not sure how I would make this work without recursion.</p>

<p>Any help is appreciated as I think I'm still failing to see the difference between the two.</p>

<pre><code>result = []

def permutation(li):
    if len(li) == 1:
        result.append(li[0])
        print (result)
        result.pop()
        return

    for i in range(0,len(li)):
        result.append(li[i])
        permutation(li[:i] + li[i+1:])
        result.pop()    

permutation([1,2,3])
</code></pre>

<p>I always liked this method: </p>

<p>Until the length of each variation in the queue equals the input's length: place the next input element in all positions of each variation</p>

<pre><code>input [1,2,3]

queue [[1]]
insert 2 in all positions of each variation
queue [[2,1],[1,2]]
insert 3 in all positions of each variation
queue [[3,2,1],[2,3,1],[2,1,3],[3,1,2],[1,3,2],[1,2,3]]
</code></pre>

python algorithm