#include
} void pingchengji (stunode * head) {total.pshuxue = Total.pshuxue head-> shuxue; total.penglish = Total.PENGLISH head-> English; total.pchinese = Total.pchinese head-> Chinese; Total. Count = Total.count 1;} class stutree / binary tree {private: stunode * root, * newnode, * currnode, * parent; void print; void zonghe (stunode * temp); int ischild (); int ischild (STUNODE * TEMP); int ischild stunode * pnode, stunode * childnode); stunode * findnode (const int rid, stunode * & parentnode); public: stutree (void); void creattree (stunode * node); void prints (void); stunode * findnode (const int RID); void insertnode; void pingjun (void); stunode * deletenode (int DID); void deletetree; ~ stutree (void);}; stutree :: stutree (void) {root = NULL; newNode = NULL; currnode = null; parent = null;} void stutree :: deletetree (stunode * temp) {if (Temp! = Null) {deletetree (Temp-> returnft ()); deletetree (TEMP-> ReturnRight ()); delete temp;}} stutree :: ~ stutree (void) {deletetree (RO OT);} void stutree :: createtree (stunode * node) // Create a binary tree {if (root == null) {root = node;} else {if (node-> getId ()
GetId ()
Stunode * stutree :: FindNode (const Int rid, stunode * & parntnode) {if (root-> getId () == rid) {parentnode = null; return root;} if (Rid
RightNode = Temp-> retURNRight (); if (leftnode == null && rightnode == null) // Temp left and right nodes {Switch (post) {case 1: ParentNode-> Insert (NULL); BREAK Case 0: ParentNode-> INSERTRIGHT (NULL); Break; Case-1: Break;} delete temp; return root;} if (leftnode! = Null && rightnode == null) // There is no right node {SWITCH (postnode); Break; case 0: Parentnode-> InsertNode; Break; Case -1: root = root-> returnft (); break;} delete temp; return;} delete temp; return; Root;} if (leftnode == null && rightnode! = null) There is no left node {switch (post) {casse 1: parentnode-> INSERTLEFT (RightNode); Break; cas 0: Parentnode-> InsertNode Break; Case -1: root = root-> retURNRight (); Break; } Delete Temp; Return Root;} IF (LeftNode! = Null && RightNode! = Null) There is {Parenode = rightnode; renode = rightnode; // renode is the replacement node while (renode-> returnveft ()! = NULL) // Find the replacement node {// The minimum node in the right sub-tree in the right child is the replacement node we are looking for Parenode = renode; // can also find the most larger node in the left subtree of the left child Renode = renode -> returnveft ();} If (renode == rightnode) // One case is: Replace node is Temp's right son {rightnode-> insertleft (leftnode);
} Else {// If you don't have the right son, you will do the following: Renode-> ReturnRight (); renode-> insertleft; renode-> insert (RightNode);} switch (post) {casse 1: root = renode; break; case 1: parentnode-> insertleft (renode); break; cas 0: Parentnode-> InsertRight (renode); break;} delete temp; return root;}} void main (void) {int Select, NID, NSHUXUE, NENGLISH, NCHINESE COUT << "2> Print a list" << endl; cout << "3> Find student << endl; cout <<" 4> INSERT A Student << Endl; cout << "5> ping jun CHENG JI "<< Endl; cout <<" 6> delete a student "<< endl; cout <<" 7> Chang student information "<< Endl COUT << "0> EXIT" << Endl; cin >> select; switch (select) {case 1: cout << "" please input a id "<< endl; cin >> NID; getLine (CIN, Space, '/ n'); cout << "please input a name" << endl; getLine (cin, nname, '/ n'); cout << "please input a shuxue" << endl; cin >> nShuxue; cout << "" please input a english "<< Endl; CIN >> NENGLISH; COUT <<" please input a Chinese "" << endl; cin >> nCHINESE
Newstudent = New Stunode (NID, NNAME, NSHUXUE, NEENGLISH, NCHINESE); if (newstudent == null) {cout << "error" << endl; exit (1);} stulist.creattree (newstudent); break; cas 2: stulist.prints (); Break; Case 3: cout << "please input a id for student" << Endl; cin >> wid; findrezult = stulist.findNode (wid); if (FindRezult! = Null) { PRINTNODE (FINDREZUT);} else {cout << "student not find << Endl;} Break; Case 4: cout <<" please input a id "<< Endl; CIN >> NID; GetLine (CIN, Space, '/ n'); cout << "please input a name" << endl; getLine (cin, nname, '/ n'); cout << "please input a shuxue" << endl; cin >> nShuxue; cout << "please input a english" << Endl; CIN >> NENGLISH; cout << "please input a Chinese" << Endl; cin >> nCHINESE; newstudent = new stunode (NID, NNAME, NSHUXUE, NENGLISH, NCHINESE) ; If (newstudent == null) {cout << "error" << endl; exit (1);} stulist.insertnode (newstudent); break; case 5: stulist.pingjun (); break; CAS E 6: COUT << "please input a id" << endl; cin >> deid; stulist.deletenode (deid); break; case 7: cout << "please input a student id for chenge << endl; cin >> NID; FINDREZULT = Stulist.FindNode (NID); cout << "20.change name" << endl; cout << "21.change shuxue << Endl; cout << 22.change english << Endl; cout << "23.change Chinese << Endl; CIN >>
SELECT; SWITCH (SELECT) {Case 20: getLine (cin, space, '/ n'); cout << "please input new name" << endl; getLine (cin, nname, '/ n'); Findrezult-> SetName (NName); Break; Case 21: COUT << "please input new shuxue" << Endl; cin >> nShuxue; findrezult-> setshuxue (nshuxue); Break; Case 22: cout << "please input new English" << endl; cin >> Nenglish; new; Break; Case 23: COUT << "" please input new Chinese "<<"; cin >> nCHINESE (NCHINESE); BREAK; } break; case 0: exit (0);}}} this program debugging environment in linux source codes follow the GPL References: C language data structure of << >> description of: William Ford William Topp the Tsinghua University. the first edition of the University community << data structure (C language) >> author: Huang Guoyu Yenai Jing Tsinghua University Press, please correct me