70道常见面试算法笔试题.docx

  1. 1、本文档共123页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
70道常见面试算法笔试题.docx

微软等面试?100题答?案1.把二元查找?树转变成排?序的双向链?表题目:输入一棵二?元查找树,将该二元查?找树转换成?一个排序的?双向链表。要求不能创?建任何新的?结点,只调整指针?的指向。10/ /6 14/ / / /4 8 12 16转换成双向?链表4=6=8=10=12=14=16。首先我们定?义的二元查?找树节点的数据?结构如下:struc?t BSTre?eNode?{int m_nVa?lue; // value? of nodeBSTre?eNode? *m_pLe?ft; // left child? of nodeBSTre?eNode? *m_pRi?ght; // right? child? of node};//引用 245 楼 tree_?star 的回复#inclu?de stdio?.h#inclu?de iostr?eam.hstruc?t BSTre?eNode?{int m_nVa?lue; // value? of nodeBSTre?eNode? *m_pLe?ft; // left child? of nodeBSTre?eNode? *m_pRi?ght; // right? child? of node};typed?ef BSTre?eNode? Doubl?eList?;Doubl?eList? * pHead?;Doubl?eList? * pList?Index?;void conve?rtToD?ouble?List(BSTre?eNode? * pCurr?ent);// 创建二元查?找树void addBS?TreeN?ode(BSTre?eNode? * pCurr?ent, int value?){if (NULL == pCurr?ent){BSTre?eNode? * pBSTr?ee = new BSTre?eNode?();pBSTr?ee-m_pLe?ft = NULL;pBSTr?ee-m_pRi?ght = NULL;pBSTr?ee-m_nVa?lue = value?;pCurr?ent = pBSTr?ee;}else {if ((pCurr?ent-m_nVa?lue) value?){addBS?TreeN?ode(pCurr?ent-m_pLe?ft, value?);}else if ((pCurr?ent-m_nVa?lue) value?){addBS?TreeN?ode(pCurr?ent-m_pRi?ght, value?);}else{//cout重复加入节?点endl;}}}// 遍历二元查?找树中序void ergod?icBST?ree(BSTre?eNode? * pCurr?ent){if (NULL == pCurr?ent){ retur?n;}if (NULL != pCurr?ent-m_pLe?ft){ergod?icBST?ree(pCurr?ent-m_pLe?ft); }// 节点接到链?表尾部conve?rtToD?ouble?List(pCurr?ent);// 右子树为空?if (NULL != pCurr?ent-m_pRi?ght){ergod?icBST?ree(pCurr?ent-m_pRi?ght);}}// 二叉树转换?成list?void conve?rtToD?ouble?List(BSTre?eNode? * pCurr?ent){pCurr?ent-m_pLe?ft = pList?Index?;if (NULL != pList?Index?){pList?Index?-m_pRi?ght = pCurr?ent;}else{pHead? = pCurr?ent;} pList?Index? = pCurr?ent;coutpCurr?ent-m_nVa?lueendl;}int main(){BSTre?eNode? * pRoot? = NULL;pList?Index? = NULL;pHead? = NULL;addBS?TreeN?ode(pRoot?, 10);addBS?TreeN?ode(pRoot?, 4);addBS?TreeN?ode(pRoot?, 6);addBS?TreeN?ode(pRoot?, 8);addBS?TreeN?ode(pRoot?, 12);addBS?TreeN?ode(pRoot?, 14);addBS?TreeN?ode(pRoot?, 15);addBS?TreeN?ode(pRoot?, 16);ergod?icBST?ree(pRoot?);retur?n 0;}//////////////////////

文档评论(0)

zhangningclb + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档