{"id":8759,"date":"2019-12-13T09:10:12","date_gmt":"2019-12-13T08:10:12","guid":{"rendered":"https:\/\/www.giusseppe.net\/blog\/?p=8759"},"modified":"2019-12-12T13:30:31","modified_gmt":"2019-12-12T12:30:31","slug":"codigo-de-permutaciones","status":"publish","type":"post","link":"https:\/\/www.giusseppe.net\/blog\/archivo\/2019\/12\/13\/codigo-de-permutaciones\/","title":{"rendered":"C\u00f3digo de permutaciones"},"content":{"rendered":"<p><code><\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">\/\/ C program to print all permutations with duplicates allowed \r\n#include &lt;stdio.h&gt; \r\n#include &lt;string.h&gt; \r\n#define OK\t1\r\n#define KO\t0\r\n\r\n  \r\n\/* Function to swap values at two pointers *\/\r\nvoid swap(char *x, char *y) \r\n{ \r\n    char temp; \r\n    temp = *x; \r\n    *x = *y; \r\n    *y = temp; \r\n} \r\n  \r\n\/* Function to print permutations of string \r\n   This function takes three parameters: \r\n   1. String \r\n   2. Starting index of the string \r\n   3. Ending index of the string. *\/\r\nvoid permute(char *a, int l, int r) \r\n{ \r\n   int i; \r\n   if (l == r) \r\n     printf(\"%s\\n\", a); \r\n   else\r\n   { \r\n       for (i = l; i &lt;= r; i++) \r\n       { \r\n          swap((a+l), (a+i)); \r\n          permute(a, l+1, r); \r\n          swap((a+l), (a+i)); \/\/backtrack \r\n       } \r\n   } \r\n} \r\n  \r\n\/* Driver program to test above functions *\/\r\nint main(int argc, char *argv[]) \r\n{ \r\n  if ((argc != 2) || (strlen(argv[1]) &gt; 10))\r\n  {\r\n    printf(\"Utilizaci\u00f3n: %s Cadena\\n\", argv[0]);\r\n    printf(\"'Cadena' no puede tener m\u00e1s de 10 caracteres.\\n\");\r\n    return KO;\r\n  }\r\n    char str[27];\r\n    strcpy(str, argv[1]);\r\n    int n = strlen(str); \r\n    permute(str, 0, n-1); \r\n    return OK; \r\n}<\/pre>\n<p><code><\/code><\/p>\n<p>&nbsp;<\/p>\n<p><code><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ C program to print all permutations with duplicates allowed #include &lt;stdio.h&gt; #include &lt;string.h&gt; #define OK 1 #define KO 0 \/* Function to swap values at two pointers *\/ void swap(char *x, char *y) { char temp; temp = *x; *x = *y; *y = temp; } \/* Function to print permutations of string This &#8230; <a title=\"C\u00f3digo de permutaciones\" class=\"read-more\" href=\"https:\/\/www.giusseppe.net\/blog\/archivo\/2019\/12\/13\/codigo-de-permutaciones\/\">Read more<span class=\"screen-reader-text\">C\u00f3digo de permutaciones<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[110],"tags":[],"class_list":["post-8759","post","type-post","status-publish","format-standard","hentry","category-tecnologia-opinion"],"_links":{"self":[{"href":"https:\/\/www.giusseppe.net\/blog\/wp-json\/wp\/v2\/posts\/8759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.giusseppe.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.giusseppe.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.giusseppe.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.giusseppe.net\/blog\/wp-json\/wp\/v2\/comments?post=8759"}],"version-history":[{"count":11,"href":"https:\/\/www.giusseppe.net\/blog\/wp-json\/wp\/v2\/posts\/8759\/revisions"}],"predecessor-version":[{"id":8770,"href":"https:\/\/www.giusseppe.net\/blog\/wp-json\/wp\/v2\/posts\/8759\/revisions\/8770"}],"wp:attachment":[{"href":"https:\/\/www.giusseppe.net\/blog\/wp-json\/wp\/v2\/media?parent=8759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.giusseppe.net\/blog\/wp-json\/wp\/v2\/categories?post=8759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.giusseppe.net\/blog\/wp-json\/wp\/v2\/tags?post=8759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}