HanG321 Blog
Be Shine, Be Smile, Be Wild
  • Home
  • Blog
    • 好文閱讀 readings
    • 生活記事 diary
    • 時事評論 commentary
    • 科技資訊 technology
    • 電腦編程 programming
    • 金融財經 finance
    • 音樂電影 music/movie
  • About

read Tree

March 6, 2006|電腦編程
Home » Blog » 電腦編程 » read Tree

ai…..Google….good? bad?
wrong way to learn

 

struct Tree{
int info;
Tree * left, * right;
};

Tree * ReadTree();
void Level(Tree *);
int IsSpecified(Tree *);
int currentNode;

const int MAX_NODES = 300;
Tree * nodes[MAX_NODES]; // grab max nodes up front

void ZeroNodes()
// postcondition: all nodes are illegal (no children, 0 info)
{
................
}

void InitNodes()
// postcondition: nodes allocated and zero'd
{
................
}

main()
{
Tree *t;

InitNodes();

while (t = ReadTree()){
if (!IsSpecified(t)){
cout << "not complete" << endl;
}
else{
Level(t);
}
}
}

void AddTree(Tree * & t, char *s, int val)
// add node with 'val' using path 's' to tree 't'
{
..................
..........
AddTree(t->left,s+1,val); // go left
}
else{
AddTree(t->right,s+1,val); // go right
}
...........
t->info = -1; // already seen it
}
}
}

Tree *ReadTree()
{
char buf[100];
Tree * t = NULL;
ZeroNodes();
while (cin >> buf){
if (strcmp(buf,"()") == 0){
break;
}
else{
buf[strlen(buf)-1] = ''; // remove ')'
char *b = buf;
while (*b != ','){ // look for comma
b++;
}
*b = '';
AddTree(t,b+1,atoi(buf+1));
}
}
return t;
}

 

 

March 6, 2006 user

Recent Posts

  • Serverless Cloud Run Development: Challenge Lab
    Serverless Cloud Run Development: Challenge LabFebruary 7, 2021
  • ionic 4: capacitor & pwa
    ionic 4: capacitor & pwaJanuary 2, 2019
  • Open file limit of tomcat and mysql in Linux server
    Open file limit of tomcat and mysql in Linux serverDecember 1, 2018

Popular Posts

  • Install XPEnology (DSM) 5.1 on ESXi 6 (HP MicroServer Gen 8)
    Install XPEnology (DSM) 5.1 on ESXi 6 (HP MicroServer Gen 8)June 8, 2015
  • assembly
    assemblyFebruary 11, 2006
  • 呢幾日個blogger 有問題….
    呢幾日個blogger 有問題….October 28, 2004
← brainstorming
我不想說我是雞 →

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.




最新文章 Recent Posts

  • Serverless Cloud Run Development: Challenge Lab
  • ionic 4: capacitor & pwa
  • Open file limit of tomcat and mysql in Linux server
  • avoid subquery in mysql update statement
  • hacktoberfest

最新留言 Recent Comments

  • admin on LikeCoin
  • Edmond on LikeCoin
  • John Smith on Install macOS High Sierra on VMware
  • admin on Install macOS High Sierra on VMware
  • nana on Install macOS High Sierra on VMware




熱門文章 Popular Posts

  • Install XPEnology (DSM) 5.1 on ESXi 6 (HP MicroServer Gen 8)
    Install XPEnology (DSM) 5.1 on ESXi 6 (HP MicroServer Gen 8) June 8, 2015
  • 呢幾日個blogger 有問題….
    呢幾日個blogger 有問題…. October 28, 2004
  • assembly
    assembly February 11, 2006
  • 新工作
    新工作 January 6, 2009
  • 失望
    失望 April 3, 2006

標籤雲 Tag Cloud

amazon CentOS chroot DD-WRT Debian Domino DSM DWA ebook ebook calibre ESXi GCP git google gradle groovy HTML5 IE Java Javascript javscript Jenkins LikeCoin Linux log LotusScript mint MySQL N36L nanoboot nginx PowerShell Qwiklabs responsive route Tomcat VMware vpn vSphere wordpress XPEnology 專欄 網絡資訊 選股 風帆

日曆 Calendar

March 2006
M T W T F S S
  « Feb   Apr »  
 12345
6789101112
13141516171819
20212223242526
2728293031  

Follow Me

Follow Us on RSSFollow Us on TwitterFollow Us on YouTube

文章存檔 Archives

Copyright © 2004-2021 hang321.net. All Rights Reserved
Go to mobile version