API中文文件:Swagger詳解
阿新 • • 發佈:2021-10-27
點選檢視程式碼
#include <stdio.h> #include <stdlib.h> typedef char dataType; typedef struct node{ dataType data; struct node *lchild,*rchild; }BinTree; /*---建立二叉樹---*/ BinTree *CreateBinTree() {/*先序建立一個二叉樹連結串列*/ BinTree *bt = NULL; char ch; ch = getchar(); if(ch!='#') { bt = (BinTree *)malloc(sizeof(BinTree)); bt->data = ch; bt->lchild = CreateBinTree(); bt->rchild = CreateBinTree(); } return bt; } void endprintfBinTree(BinTree *bt) { if(bt != NULL) {/*---後序二叉樹遍歷---*/ printfBinTree(bt->lchild); printfBinTree(bt->rchild); printf("%c",bt->data); } } void firstprintfBinTree(BinTree *bt) { if(bt != NULL) {/*---先序二叉樹遍歷---*/ printf("%c",bt->data); printfBinTree(bt->lchild); printfBinTree(bt->rchild); } } void middelprintfBinTree(BinTree *bt) { if(bt != NULL) {/*---中序二叉樹遍歷---*/ printfBinTree(bt->lchild); printf("%c",bt->data); printfBinTree(bt->rchild); } } /*---按中序遍歷的方法求葉子節點的總數---*/ void CountLeaf(BinTree *t,int* count) { if(t) { if(!(t->lchild)&&!(t->rchild)) { (*count)++; CountLeaf(t->lchild,count); CountLeaf(t->rchild,count); } } } /*---求二叉樹深度---*/ int Depth(BinTree *t) { int h1,hr; if(!t) return 0; else { h1 = Depth(t->lchild); hr = Depth(t->rchild); if(h1>=hr) return h1+1; else hr+1; } } int main() { BinTree *bt; bt = CreateBinTree(); firstprintfBinTree(bt); middelprintfBinTree(bt); endprintfBinTree(bt); }