欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門教程網(wǎng)!

C語(yǔ)言

當(dāng)前位置:主頁(yè) > 軟件編程 > C語(yǔ)言 >

排列和組合算法的實(shí)現(xiàn)方法_C語(yǔ)言經(jīng)典案例

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語(yǔ)言|點(diǎn)擊: 次

排列和組合算法是考查遞歸的常見(jiàn)算法,這兩種算法能用遞歸簡(jiǎn)潔地實(shí)現(xiàn)。

本人在經(jīng)過(guò)多次摸索和思考之后,總結(jié)如下,以供參考。

程序代碼如下:

#include <stdio.h>
#include <stdlib.h>

char array[] = "abcd";

#define N 4
#define M 3
int queue[N] = {0};
int top = 0;
int flag[N] = {0};
 
 void perm(int s, int n)
 {
   int i;
 
   if (s > n)
   {
     return;
   }
 
   if (s == n)
   {
     for (i = 0; i < n; i++)
     {
       printf("%c", queue[i]);
     }
     printf("\t");
     return ;
   }
 
   for (i = 0; i < n; i++)
   {
     if (flag[i] == 0)
     {
       flag[i] = 1;
       queue[s] = array[i];
       perm(s+1, n);
       flag[i] = 0;
     }
   }
 }
 
 void comb(int s, int n, int m)
 {
   int i;
 
   if (s > n)
     return ;
 
   if (top == m)
   {
     for (i = 0; i < m; i++)
     {
       printf("%c", queue[i]);
     }
     printf("\t");
     return ;
   }
 
   queue[top++] = array[s];
   comb(s+1, n, m);
   top--;
   comb(s+1, n, m);
 
 }
 
 int main()
 {
   printf("\nperm():\n");
   perm(0, N);
   printf("\ncombination():\n");
   comb(0, N, M);
   printf("\n");
   return 0;
 }

運(yùn)行結(jié)果:

perm():
abcd  abdc  acbd  acdb  adbc  adcb  bacd  badc  bcad  bcda
bdac  bdca  cabd  cadb  cbad  cbda  cdab  cdba  dabc  dacb
dbac  dbca  dcab  dcba
combination():
abc   abd   acd   bcd

以上就是小編為大家?guī)?lái)的排列和組合算法的實(shí)現(xiàn)方法_C語(yǔ)言經(jīng)典案例的全部?jī)?nèi)容了,希望對(duì)大家有所幫助,多多支持我們~

上一篇:C語(yǔ)言之雙向鏈表詳解及實(shí)例代碼

欄    目:C語(yǔ)言

下一篇:C/C++字符串查找函數(shù)全面了解

本文標(biāo)題:排列和組合算法的實(shí)現(xiàn)方法_C語(yǔ)言經(jīng)典案例

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/2048.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有