# 微软等公司数据结构面试题1

tree.h
typedef struct BSTreeNode {
int m_value;
struct BSTreeNode *m_left ;
struct BSTreeNode *m_right;
} bstTreeNode;
class ActTree{
public:
ActTree();
void InsertValue() ;
void DeleteValue() ;
void Sort();
void PrintTree();
void PrintNode(bstTreeNode *node);
void ChangeDoubleList();
void Change(bstTreeNode *node);
void PrintList();
private:
bstTreeNode *currentList;
bstTreeNode *root;
bstTreeNode *first;
};
tree.cpp
#include "tree.h"
#include <cstdlib>
#include <iostream>
ActTree::ActTree()
{
root = NULL;
first = NULL;
// std::cout<<"construction error!"<<std::endl;
}
void ActTree::InsertValue()
{
int temp,flag = 0;
std::cout<<"Input  ";
std::cin>>temp;
bstTreeNode *pnow  = root;
bstTreeNode *pparent  = root;
while( pnow ) {
if( pnow->m_value == temp ){
flag = 1;
pnow = NULL;
std::cout<<"%d has existed!"<<std::endl;
}
else if( pnow->m_value > temp ) {
pparent = pnow ;
pnow = pnow ->m_left ;
}
else {
pparent = pnow ;
pnow = pnow ->m_right ;
}
}
if(!flag) {
if( bstTreeNode *ptemp = (bstTreeNode *) malloc(sizeof (bstTreeNode))) {
ptemp->m_value = temp;
ptemp->m_left = ptemp->m_right = NULL;
if (pparent)
{
if( pparent->m_value > temp )
pparent->m_left =ptemp ;
else
pparent->m_right =ptemp ;
}
else {
root = ptemp;
}
}
else
std::cerr<<"malloc failed!"<<std::endl;
}
}
void ActTree::PrintTree()
{
PrintNode(root);
}
void ActTree::PrintNode(bstTreeNode *node)
{
if( node ){
PrintNode(node->m_left);
std::cout<<node->m_value<<" ";
PrintNode(node->m_right);
}
}
{
if (!first) {
first = node ;
currentList =first;
first->m_left = NULL;
first->m_right = NULL;
}
else {
currentList->m_right = node;
node->m_left =currentList;
node->m_right =NULL;
currentList = node;
}
}
void ActTree::Change(bstTreeNode *node)
{
if (node) {
Change(node->m_left);
bstTreeNode * right = node ->m_right;
Change(right);
}
else
return ;
}
void ActTree::ChangeDoubleList()
{
this->Change(root);
}
void ActTree::PrintList()
{
bstTreeNode * node = first;
while(node) {
std::cout<<node->m_value<<"=";
node = node->m_right;
}
}
main.cpp
#include "tree.h"
#include <iostream>
int main()
{
ActTree test ;
int select;
//while (std::cin<<select )
test.InsertValue();
test.InsertValue();
test.InsertValue();
test.InsertValue();
test.PrintTree();
std::cout<<std::endl;
test.ChangeDoubleList();
test.PrintList();
getchar();
getchar();
return 0;
}

#### 微软公司等数据结构+算法面试100题

2016-07-11 11:02:22

#### 微软等公司数据结构+算法面试题系列

2010年11月28日 8KB 下载

#### 2017微软面试算法题回顾

2017-04-25 12:15:54

#### 微软等公司数据结构+算法面试100题、分析、考点、解答（第1~100题）

2014-10-27 01:27:14

#### 算法与数据结构——微软笔试题

2018-01-27 22:24:36

#### BAT等公司必问的8道Java经典面试题，你都会了吗？

2018-06-19 17:49:38

#### 复旦硕士从国内直接找到美国微软、谷歌、fb、hulu工作！五场面试题目+经验分享

2015-08-05 08:46:33

#### 各大公司数据结构与算法面试题解答(一)

2012-11-19 21:19:21

#### 微软等公司的面试题

2018年01月11日 112KB 下载