generate all permutations of string
C
void perm(char a[], int level){
static int flag[10] = {0};
static char res[10];
// If we are the last character of the input string
if(a[level] == '\0'){
// First we assign stopping point to result
res[level] = '\0';
// Now we print everything
for(int i = 0; res[i] != '\0'; ++i){
printf("%c", res[i]);
}
printf("\n");
++counter;
}
else{
// Scan the original string and flag to see what letters are available
for(int i = 0; a[i] != '\0'; ++i){
if(flag[i] == 0){
res[level] = a[i];
flag[i] = 1;
perm(a, level + 1);
flag[i] = 0;
}
}
}
}
int main(){
char first[] = "abc";
perm(first, 0);
return 0;
}void permute(string a, int l, int r)
{
// Base case
if (l == r)
cout<<a<<endl;
else
{
// Permutations made
for (int i = l; i <= r; i++)
{
// Swapping done
swap(a[l], a[i]);
// Recursion called
permute(a, l+1, r);
//backtrack
swap(a[l], a[i]);
}
}
}
Also in C:
- Title
- vue cdn
- Category
- C
- Title
- disable gnu++11 option
- Category
- C
- Title
- print in c
- Category
- C
- Title
- uninstall elgg from hostgtor
- Category
- C
- Title
- c get first n characters of string
- Category
- C
- Title
- tkinter create_line
- Category
- C
- Title
- c vs python
- Category
- C
- Title
- reset c array to zero
- Category
- C
- Title
- java.lang.SecurityException: Permission denied (missing INTERNET permission?)
- Category
- C
- Title
- c check if char is an operator
- Category
- C
- Title
- version of libgcc
- Category
- C
- Title
- left me on read
- Category
- C
- Title
- div
- Category
- C
- Title
- #include<stdlib.h>
- Category
- C
- Title
- Declare macro
- Category
- C
- Title
- linux directory commands
- Category
- C
- Title
- add border to image android
- Category
- C
- Title
- buscar caracter
- Category
- C
- Title
- powershell list big files
- Category
- C
- Title
- fibonacci series using recursion
- Category
- C
- Title
- pass the pointer in C
- Category
- C
- Title
- xmlns='' was not expected
- Category
- C
- Title
- docker images command
- Category
- C
- Title
- what is strikethrough in markdown
- Category
- C
- Title
- sbatch array set max jobs at once
- Category
- C
- Title
- hello world
- Category
- C
- Title
- '&&' within '||'
- Category
- C
- Title
- diferencia entre * y & en c
- Category
- C
- Title
- c program to find the sum of given number
- Category
- C
- Title
- CL/cl.h: No such file or directory
- Category
- C
- Title
- vbl share price
- Category
- C
- Title
- coin row problem in linear time
- Category
- C
- Title
- command line arguments c
- Category
- C
- Title
- c list
- Category
- C
- Title
- change plot line color in matplotlib
- Category
- C
- Title
- double return type in c
- Category
- C
- Title
- accessing elements 2D array using pointers
- Category
- C
- Title
- functions return type in c
- Category
- C
- Title
- generate all permutations of string
- Category
- C
- Title
- how to find the ith row of pascal's triangle in c
- Category
- C
- Title
- california
- Category
- C
- Title
- allocate memory c
- Category
- C
- Title
- Switch Mode C Programming
- Category
- C
- Title
- remove an element from a set
- Category
- C
- Title
- convert string to float c
- Category
- C
- Title
- c printf right pad with space
- Category
- C
- Title
- enum c
- Category
- C
- Title
- classification report to excel
- Category
- C
- Title
- \0 in c
- Category
- C
- Title
- wait function in c
- Category
- C
- Title
- get regedit value cmd
- Category
- C
- Title
- read a document in c getting name from console
- Category
- C
- Title
- c defined value sum
- Category
- C
- Title
- strtoul C
- Category
- C
- Title
- random en c
- Category
- C
- Title
- what is the meaningof noremap
- Category
- C
- Title
- c check if char is number
- Category
- C
- Title
- how to pass an array to a thread in c?
- Category
- C
- Title
- remove element queue
- Category
- C
- Title
- mediawiki upload size
- Category
- C
- Title
- passing 2d array as parameter to function in c
- Category
- C
- Title
- how to feed a char array to function in C
- Category
- C
- Title
- prime number
- Category
- C
- Title
- how to get random numbers in c
- Category
- C
- Title
- delete string function in c
- Category
- C
- Title
- root in C
- Category
- C
- Title
- Fibonacci program c pthread
- Category
- C
- Title
- c printf uint32_t
- Category
- C
- Title
- doubly linked list c
- Category
- C
- Title
- how to store a user input with spaces in c
- Category
- C
- Title
- windowns 10 allow ping
- Category
- C
- Title
- battlefield4u.com
- Category
- C
- Title
- c value set to zero __memmove_avx_unaligned_erms
- Category
- C
- Title
- get_session` is not available when using TensorFlow 2.0.
- Category
- C
- Title
- c check if file was created
- Category
- C
- Title
- for loop c
- Category
- C
- Title
- Couldn't create temporary file to work with
- Category
- C
- Title
- function pointer c
- Category
- C
- Title
- objective c swizzle method
- Category
- C
- Title
- duplicar cadena
- Category
- C
- Title
- assert() in c
- Category
- C
- Title
- how to open a website in c
- Category
- C
- Title
- c substring
- Category
- C
- Title
- atoi
- Category
- C
- Title
- how to only show tenths place in c
- Category
- C
- Title
- bella ciao lyrics
- Category
- C
- Title
- ModuleNotFoundError: No module named 'tensorboardX'
- Category
- C
- Title
- read a binary file c
- Category
- C
- Title
- debian install npm
- Category
- C
- Title
- sdl bouton
- Category
- C
- Title
- program using if statement in c whether numnber is less eqaul to greater than 50
- Category
- C
- Title
- C largest unsigned int
- Category
- C
- Title
- how to check where the last char is in a string c
- Category
- C
- Title
- lazer codechef
- Category
- C
- Title
- text wrap terminal colour
- Category
- C
- Title
- char to int c
- Category
- C
- Title
- download android ndk r 16
- Category
- C
- Title
- how to open chrome using cmd
- Category
- C
- Title
- can we write a program without main in c
- Category
- C
- Title
- how to sleep in c
- Category
- C