- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
全排列等(The whole arrangement etc.)
The first part, the whole arrangement problem
53. The arrangement of strings.
Title: enter a string to print all the permutations of the characters in that string.
For example, input string ABC, which outputs all the strings that can be sorted by character a, b, and c
ABC, acb, bac, bca, cab and cba.
This topic was first organized in last years Microsoft interview question 53, and the second one was compiled from Microsoft, Google and other companies for excellent interview questions and solutions [61-70]. 67. This problem has appeared in baidu pen test this year. Ok, lets analyze the problem.
One, recursive implementation
Each element is selected from the collection, as the first element in the arrangement, and then the remaining elements are arranged in a complete array, so that the whole arrangement of all elements is obtained. To take a full permutation of string ABC, we can do this:
So lets fix a, and were going to get the permutation of BC, and then, after were done, were going to swap a and b, and we get bac
So Im going to fix b, and Im going to find the line in the back of ac, and Ill put it in the first place, and Ill get the cba
So Im going to fix c, and Im going to find the arrangement of the following ba. The code can be written as follows:
The template typename T
Void CalcAllPermutation_R (T perm [], int first, int num)
{
If (num = 1) {
The return;
}
For (int I = first; I first + num; + + I) {
Swap (perm [I], perm [first]);
CalcAllPermutation_R (perm, first + 1, num - 1);
Swap (perm [I], perm [first]);
}
}
Or: view plaincopy to clipboardprint? Void Permutation (char * pStr, char * pBegin);
Void Permutation (char * pStr)
{
The Permutation (pStr, pStr);
}
Void Permutation (char * pStr, char * pBegin)
{
If (! PStr | |! PBegin)
The return;
If (* pBegin = = \ 0)
{
Printf ( % s \ n , pStr);
}
The else
{
For (char * pCh = pBegin; * pCh! = \ 0; + + pCh)
{
/ / swap pCh and pBegin
PCh char temp = *;
PCh * = * pBegin;
* pBegin
您可能关注的文档
- 系统盘(c盘)减肥清理大全(xp适用)xp(System disk (c disk) weight loss cleaning (xp applies) xp).doc
- 系统说明书(System specification).doc
- 箱包知识文件(Suitcase knowledge file).doc
- 箱涵工程施工方案(Box culvert engineering construction scheme).doc
- 用avr单片机io口模拟i2c总线操作at24cxx的通用程序(Using avr MCU IO to simulate the general procedure of i2c bus operation at24cxx).doc
- 用c++模拟曲柄滑块装置(Simulate crank slider with c + +).doc
- 用cool edit pro等软件为歌曲做人声消除(Use software like cool edit pro to eliminate the sound of songs).doc
- 用ps制作漫画用网点(Use ps to make comics).doc
- 用点规范(Use a little specifications).doc
- 用光-影视摄像的效果)(Lighting - video camera effect).doc
- 全球化背景下的中国文化(Chinese culture under the background of globalization).doc
- 全球左翼论坛综述(Global leftwing BBS review).doc
- 全日制普通高中语文教材目录(Full time ordinary high school Chinese textbook catalogue).doc
- 全时四驱,实时四驱,分时四驱对比(The total time 4 drive, real time 4 drive, time 4 drive comparison).doc
- 全国咨询工程师继续教育考试93分(National consulting engineers continue to score 93 on education).doc
- 全系魔法大全(It's all magic).doc
- 全新版大学英语综合教程4课后练习 中翻英(New edition of college English comprehensive tutorial 4).doc
- 全站仪自由设站的应用及精度分析(Application and precision analysis of free station of total station).doc
- 全面细致 教你闪光灯摄影基础知识(Comprehensive and detailed knowledge of flash photography basics).doc
- 入境英语(Entry into English).doc
最近下载
- 《混凝土结构加固设计规范》GB50367.pdf VIP
- 《精神疾病诊断与统计手册》DSM5.PDF VIP
- 2冷疗技术15课件讲解.pptx VIP
- 海姆立克急救法操作考核标准.doc VIP
- JJG 195-2019 连续累计自动衡器(皮带秤).pdf VIP
- 专项治理整改落实及长效机制建设情况报告().pdf VIP
- TD∕T 1087-2023 主体功能区优化完善技术指南.pdf
- (完整word版)数独题目100题(可打印).doc VIP
- 0604-会计专业国家技能人才培养工学一体化课程标准(试用).docx VIP
- 04.汉杂事秘辛.一卷.汉.阙名撰.明崇祯时期汲古阁刊本.pdf VIP
文档评论(0)