侧边栏壁纸
博主头像
王小木人

这是很长,很好的一生

  • 累计撰写 141 篇文章
  • 累计创建 43 个标签
  • 累计收到 7 条评论

目 录CONTENT

文章目录

求一个长度为n的数组中长度为m的所有排列组合

王小木人
2021-05-22 / 0 评论 / 0 点赞 / 936 阅读 / 630 字

//求一个长度为n的数组中长度为m的所有排列组合。

#include <iostream>
#include <stack>
using namespace std;
stack<string> st;
void Grial(string a[], int m,int n,int length)
{
    if (st.size() == length)
    {
        stack<string> temp = st;
        while (temp.empty() == false)
        {
            cout << temp.top() << " ";
            temp.pop();
        }
        cout << endl;
        return;
    }
    else
    {
        for (int i = m; i < n; i++)
        {
            st.push(a[i]);
            Grial(a, i+1,n,length);
            st.pop();
        }
    }
}
int main()
{
    string a[] = {"A","B","C","D","E"};
    Grial(a,0, sizeof(a) / sizeof(int),2);
}
0

评论区