-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (43 loc) · 691 Bytes
/
main.cpp
File metadata and controls
54 lines (43 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// StrPermutation.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
void Permutation(char *pStr, char *pBegin)
{
if ('\0' == *pBegin)
{
cout << pStr << endl;
}
else
{
for (char *pCha = pBegin; *pCha != '\0';++pCha)
{
char temp = *pCha;
*pCha = *pBegin;
*pBegin = temp;
Permutation(pStr, pBegin+1);
temp = *pCha;
*pCha = *pBegin;
*pBegin = temp;
}
}
}
void Permutation(char *pStr)
{
if (nullptr == pStr)
{
return;
}
Permutation(pStr, pStr );
}
int main()
{
char m[5] = { "abcd" };
cout << m << endl;
Permutation(m);
system("pause");
return 0;
}