You are viewing a single comment's thread. Return to all comments →
#include <stdio.h> #include <stdlib.h> #include <string.h> void swap(char **s,int i, int j) { char *temp = s[i]; s[i]= s[j]; s[j] = temp; } void reverse(char **s, int start, int end ) { while(start < end) { swap(s, start++,end--); } } int next_permutation(int n, char **s) { for(int i=n-2;i>-1;i--) { if(strcmp(s[i+1],s[i])>0) { for(int j=n-1;j>i;j--) { if(strcmp(s[j],s[i])>0) { swap(s,i,j); reverse(s,i+1,n-1); return 1; } } } } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Permutations of Strings
You are viewing a single comment's thread. Return to all comments →