Upline topic 3

xiaoxiao2021-03-06  23

#include

TypedEf struct node {int data; struct node * left; struct node * right;} node; void print (node ​​* p) {if (p! = null) {print (p-> left); printf ("% D / N ", p-> data); Print (p-> right);}} void main () {int N; node * head, * f, * p, * q; scanf ("% d ", & n); Head = (node ​​*) malloc (sizeof (node)); head-> data = n; head-> left = null; head-> right = null; scanf ("% d", & n); while (n! = -1) {p = (node ​​*) malloc (sizeof (node));

P-> DATA = N; P-> LEFT = NULL; P-> Right = NULL; Q = Head; f = q; while (q! = null) {if (n data) {f = q ; Q = q-> left; Continue;} if (n> Q-> DATA) {f = q; q = q-> Right; Continue;}} if (n data) f-> Left = p; if (n> f-> data) f-> Right = P; scanf ("% d", & n);} print (head);}

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

New Post(0)