(小公尺)1. 設計乙個演算法,把乙個排序二叉樹,轉化成乙個排序的雙向鍊錶,要求不能建立任何新的節點,只調整指標指向。
#include #include #include using std::cout;
using std::cin;
using std::endl;
struct bsnode
;//定義各種用到資料型別
typedef bsnode* bstree;
typedef bsnode* dlist;
typedef bsnode dlnode;
//往二叉搜尋樹tree中插入值為data的結點
bstree insertnode(bstree tree, int data);
//把二叉搜尋樹tree轉化成雙向鍊錶,返回頭結點
dlist bstreetolist(bstree tree);
//遍歷二叉搜尋樹tree的各個結點,並進行指標調整
void convertnode(bstree tree, bsnode **last_node);
//查詢二叉搜尋樹tree的最左結點
bsnode* findleftmostnode(bstree tree);
//以中序輸出二叉搜尋樹tree
void printbitree(bstree tree);
//輸出鍊錶
void printlist(dlist list);
bstree insertnode(bstree tree, int data)
//插入在其右子樹中
else if(tree->data < data)
tree->right = insertnode(tree->right, data);
//插入在其左子樹中
else if(tree->data > data)
tree->left = insertnode(tree->left, data);
return tree;
}dlist bstreetolist(bstree tree)
bsnode* findleftmostnode(bstree tree)
void convertnode(bstree tree, bsnode **last_node)
void printbstree(bstree tree)
void printlist(dlist list)
}int main()
cout << "\nthe bstree is: " << endl;
printbstree(tree);
//進行轉換
tree = bstreetolist(tree);
cout << "\nbitree to list: "<< endl;
printlist(tree);
return 0;
}
C語言名企面試題
5位運動員參加了10公尺臺跳水比賽,有人讓他們 比賽結果 a選手說 b第一,我第三。b選手說 我第二,e第四。c選手說 我第一,d第二。d選手說 c最後,我第三。e選手說 我第四,a第一。比賽結束後,每位選手都說對了一半,請程式設計確定比賽的名次。define crt secure no warni...
關於C語言的名企面試題
1.編寫 模擬三次密碼輸入的場景 define crt secure no warnings 1 include include int main if i 3 else return 0 2.編寫乙個程式,可以一直接收鍵盤字元,如果是小寫字元就輸出對應的大寫字元,如果接收的是大寫字元,就輸出對應的...
IT名企面試 騰訊筆試題
const的含義及實現機制,比如 const int i,是怎麼做到i只可讀的?const用來說明所定義的變數是唯讀的。這些在編譯期間完成,編譯器可能使用常數直接替換掉對此變數的引用。初探編譯器static const之實現原理 到商店裡買200的商品返還100優惠券 可以在本商店代替現金 請問實際...