Novice: > A few days ago, the following errors occurred when writing a program. Please, please, master, help me see. I hope c

xiaoxiao2021-03-06  64

Question: Design a middle-order clue traversal class. It is designed to consider the design needs of the pre-sequence line versus history and rear sequence transcripts in the future, and require the data domain of the node as a CHAR type. Built an Inbitree project (WIN 32 Console Application) and create an Inbitree file (C Source File). The code of the program is as follows: // bitrthnode.h # include #include

Class threadITERATOR; Class INTHREADITERATOR;

class bitrthnode {friend threaditerator; friend inthreaditerator; private: int leftthread; int rightthread; bitrthnode * leftchild; bitrthnode * rightchild; char data; public: bitrthnode (): leftthread (0), rightthread (0), leftchild (NULL), rightchild (NULL) {} bitrthnode (const char & item, bitrthnode * left = NULL, bitrthnode * right = NULL): data (item), leftchild (left), rightchild (right), leftthread (0), rightthread (0) {} }; // threaditerator.hclass threaditerator // iterate clues class {protected: bitrthnode * root; bitrthnode * current; int nextcomplete; public: threaditerator (bitrthnode * tree); int endofnext (void) const {return nextcomplete;} char data ( Void);}; threaditerator :: threaditrator (bitrthnode * Tree) {root = tree; current = root; if (Tree == null) NextComplete = 1; else nextcomplete = 0;} char threadItem :: data (void) {i (current == null) {cout << "binary tree!" << endl; exit (1);} return current-> data; cout << "data: << Current-> Data <<}

//inthreaditerator.h/*#include * /

class inthreaditerator: public threaditerator // preorder class {private: void inthread (bitrthnode * & current, bitrthnode * & pre); void creatinthread (); public: inthreaditerator (bitrthnode * tree): threaditerator (tree) {creatinthread ();} void first (void); void next (void);}; void inthreaditerator :: inthread (bitrthnode * & current, bitrthnode * & pre) {if (! current = NULL) {inthread (current-> leftchild, pre); if (current -> leftchild == null) {current-> leftchild = pre; current-> leftthread = 1;} if (pre-> rightchild == null) {pre-> Rightchild = 4; pre-> rightthread = 1;} pre-> = current; inthread (current-> rightchild, pre);}} void inthreaditerator :: creatinthread () {bitrthnode * t = root; root = new bitrthnode (); root-> leftthread = 0; root-> rightthread = 1; IF (t == null) {root-> limited = root; root-> rightcled = root;} else {current = T; root-> leftchild = T; root-> leftthread = 0; bitrthnode * pre = root; inthread (current, pre); pre-> Rightchild = root; pre-> rightthread = 1; root-> rightchild = pre; root-> rightthread = 1;}} void INTHREADITERATOR :: First (void) {current = root; if (current == root) NextComplete = 1; else nextcomplete = 0;} void INTHREADITERATOR :: Next (void) {if (NEXTCOMPLETE == 1) {CERR << " Has arrived in the binary tail! "<< endl; exit (1);} Bitrthnode * p = current-> rightchild; if (current-> rightthread == 0) While (p-> leftthread == 0) P = P-> Leftchild; current = p; if (current == root) NextComplete = 1;}

#include / * # include "inthreaditerator.h" #include "bitrthnode.h" * / bitrthnode * gettrthnode (char item, bitrthnode * left = NULL, bitrthnode * right = NULL, int leftthread = 0, int rightthread = 0); void makecharthtree (bitrthnode * & root); void printchar (char item); void main () {bitrthnode * root2; makecharthtree (root2); inthreaditerator myinthreaditer (root2); cout << "in order binary tree traversal sequence To: "; for (MyInThreaditer.first ();" MyinThreaditer.extOfNext (); MyInThreaditer.next ()) cout << MyinThreaditer.data () << ";

转载请注明原文地址:https://www.9cbs.com/read-86560.html

New Post(0)