平衡二叉树c语言代码(Balanced two fork tree c language code).docVIP

  • 4
  • 0
  • 约6.22千字
  • 约 20页
  • 2017-10-06 发布于河南
  • 举报

平衡二叉树c语言代码(Balanced two fork tree c language code).doc

平衡二叉树c语言代码(Balanced two fork tree c language code)

平衡二叉树c语言代码(Balanced two fork tree c language code) [ * Program Author: monkeylee Program name: two tree balance factor Program function: randomly generate the number of integers required by users, generate two fork tree (without duplication), Can generate, traverse, find two fork tree, and dynamic search, If the node is not found, the value is added to the tree It can display the generation sequence, balance factor (failure) and node value of the node * / #includestdio.h #includestdlib.h #includetime.h / / self reference structure Struct treeNode { Int data; / / node value Int balance; / / balance factor Int order; / / build order Struct treeNode *left; / / pointer to the left sub tree Struct treeNode *right; / / pointer to the right subtree. Struct treeNode *father; }; / * * / END structure definition Typedef struct treeNode TreeNode; Typedef TreeNode * TreeNodePtr; The function prototype / * * / Void insertNode (TreeNodePtr rootPtr, int value, int order); / / insert node Void inOrder (TreeNodePtr rootPtr); / / in order traversal Int (instructions); / / menu Void search (TreeNodePtr rootPtr, int value, int n); / / search //---------------------------------------------------------------------------------- The main function of / * * / Void, main () { Int item; / / the data to be operated Int choices; / / storage mechanism with variable Int i; / / loop counter Int n; / / the number of nodes TreeNodePtr rootPtr=NULL; / / tree is empty in the beginning While (choices=instructions ()) { Switch (choices) { Case 1: RootPtr=NULL; Printf (enter the number of nodes to generate two forks); Scanf (%d, n); If (n=0) { Printf (the number of input nodes must be greater than or equal to 1\n); Break; } Srand (time (NULL)); For (i=1; i=n; i++) { Item=rand ()% (10*n); InsertNode (rootPtr, item, I); }/*END for*/ Break; Case 2: Printf (preorder traversal: \n); If (rootPtr==NULL) Break; InOrder (rootPtr); Printf (\n); Break; Case 3: Printf (enter the number to be found); Scanf (%d, item);

文档评论(0)

1亿VIP精品文档

相关文档