Works now. Has anyone any clue to why the previous version didn't produce correct result?
--
#Compiler PBCC 6.04
#Compile Exe
#Dim All
#Register None
%Debug = 1&
'#Include Once "Debug.bi"
%USEMACROS = 1
#Include Once "Win32Api.inc"
'------------------------------------------------------------------------------
Function PBMain () As Long
Local s As String
s = "ABC"
permute(s, 0, Len(s)-1)
? "Please, press a key to end the program..."
WaitKey$
End Function
'/* Function to print permutations of string
' This function takes three parameters:
' 1. String
' 2. Starting index of the string
' 3. Ending index of the string. */
Sub permute(ByVal a As String,ByVal n As Long,ByVal r As Long)
Local i As Long
Local s1 As Byte Ptr
s1 = StrPtr(a)
If n = r Then
? a
Else
For i = n To r
Swap @s1[n],@s1[i] 'a+n,a+i
Call permute(a,n+1,r)
Swap @s1[n],@s1[i] 'a+n,a+i) '; //backtrack
Next
End If
End Sub