给出一个函数来输出一个字符串的所有排列。
来源:互联网 发布:顶级域名的含义 编辑:程序博客网 时间:2024/05/08 20:11
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <iostream>
#include <vector>
using namespace std;
char *p = "abcde";
vector<int> st;
/**找index以后的、没有在st中的数。
*如果不存在则返回-1
*/
int nextVal(int index)
{
int len = strlen(p);
vector<int>::iterator it;
for(int i = (index + 1); i < len; i++ )
{
for(it = st.begin(); it < st.end(); it++)
{
if(p[*(it)] == p[i]) break;
}
if(it >= st.end())
{
return i;
}
}
return -1;
}
/**
*z在屏幕上输出vector st的内容
*/
void printVector()
{
vector<int>::iterator it;
for(it = st.begin(); it < st.end(); it++)
{
cout <<*it << " ";
}
cout << endl;
}
/**
*输出p字符串中的字符的排列
*/
void arrange(char *p)
{
assert(p != NULL);
int len = strlen(p);
int val;
int ret;
int temp;
int temp2;
int count = 0;
while(true)
{
temp = (len - st.size());
for(int i = 0; i < temp; i++)
{
temp2 = nextVal(-1);
st.push_back(temp2);
}//end of for
printVector();
cout << "the count is" << ++count << endl;
while(st.size() != 0)
{
val = *(st.end()-1);
st.pop_back();
ret = nextVal(val);
if(ret != -1)
{
st.push_back(ret);
break;
}
else
{
}
}//end of while
if(st.size() ==0)
{
break;
}
}//end of while
}//end of arrange
int main()
{
arrange(p);
return 1;
}
- 给出一个函数来输出一个字符串的所有排列。
- 给出一个函数来输出一个字符串的所有排列
- 给出一个函数来输出一个字符串的所有排列
- 给出一个函数来输出一个字符串的所有排列
- 给出一个函数来输出一个字符串的所有排列。
- 给出一个函数来输出一个字符串的所有排列
- 给出一个函数来输出一个字符串的所有排列
- 算法40(字符串的排列,给出一个函数来输出一个字符串的所有排列)
- 70 给出一个函数来输出一个字符串的所有排列
- 3、给出一个函数输出字符串的所有排列
- 笔试题:给出一个函数来输出字符串的所有排列
- 微软等数据结构+算法面试100题(2)--给出一个函数来输出一个字符串的所有排列
- 【递归】输出一个字符串的所有排列
- 写一个函数输出一个字符串中的所有排列
- 给定一个字符串,输出其所有的可能排列
- 给出一个函数来合并两个字符串A和B
- C++ 求一个字符串的所有排列
- 打印一个字符串的所有排列。
- 一位女生的心声
- 终于搞定了rh9内核升至2.6.12后困扰已久的鼠标灵敏度问题......
- Eclipse GEF 开发之:当图形editor被更改时Enable "Save" action
- 我的个人资料
- U2TP学习随笔(一)
- 给出一个函数来输出一个字符串的所有排列。
- 请教各位高手一个VC++中有关声音文件的一个问题
- 一个问题卡了我四天
- [转]何处是New Age天堂-新世纪音乐环球之旅(一)
- KTable:比SWT 自己的table强大的table
- 喻世明言 第三十一卷 闹阴司司马貌断狱(讲三国是如何开始的)
- 实用小工具
- 生活中值得高兴的事情
- 选数程序