Home > Back-end >  Big help binary tree to create card dead
Big help binary tree to create card dead

Time:09-22

dear bosses, I was in trouble  , want to for ten thousand years, to find the problem in ten thousand, don't find out the issues required to exploit the random number generator to create an array, then the array into a binary tree, and then I go card   , stuck in a coma in ten thousand, to find a lot of code also look not to understand, cannot 1 contrast reason, only to ask you, invincible bosses, before it is put below the compiler content

[size=24 px] [size=13 px]
 H:, data structure and algorithm of course practice, basic framework - three \ P5 CPP In function 'BiTNode * init1 (BiTNode *)' : 
157 H: 28, data structure and algorithm of course practice, basic framework - three \ P5 CPP [Error] invalid conversion from 'int' to 'int * [- fpermissive]
5 H: 91, data structure and algorithm of course practice, basic framework - three \ P5 CPP [Note] the initializing argument 1 of 'int init0 (int *)'
[/size] [/size]

/* 
The source file name: P5. CPP
Function: binary tree operations
1, the realization of binary tree to create;
2, using a recursive method first order, in sequence, after the sequence traversal Tree as the hands of binary Tree;
3, write a recursive algorithm, count the number of leaf nodes in the binary tree;
4, write a recursive algorithm, calculate the depth of a binary tree;
5, write a recursive algorithm, the binary tree of all nodes in the left and right subtrees exchange;
6, the use of random number sequence in the array elem (0 means to end, not including 0), generated with the hands of the Tree binary sort Tree;
7, in a Tree to find the nodes in the hands of binary sort Tree;
8, from the Tree to delete nodes in the hands of binary sort Tree (for all kinds of the location of the node);
9, with a recursive algorithm, first sequence traversal Tree as the hands of a binary Tree;
Tip: use an array BiTNode * stack (Max) constitute the stack, use the stack functionality,
10, the binary Tree for Tree root pointer, starting from the root node, step by step from left to right the output data of each node
*/
//# include & lt; Iostream. H>
//# include & lt; Iomanip. H>
#include
#include
#include
#include
#include
#include
using namespace std;

Struct BiTNode//binary tree node type, define the binary tree structure about pointer
{
int data;//data
Int tem1, tem2;//auxiliary data (the internship not)
BiTNode * left;//left subtree pointer
BiTNode * right;//right subtree pointer
};
BiTNode MYTREE;
BiTNode * Tree;//this program operation of binary tree root pointer!!!!!!

Const int Max=100;
Int elem (Max);//store the original data


Int init0 (int the list []);
Void showBinTree (BiTNode * Tree);
BiTNode * init1 (BiTNode * Tree);//the function pointer from the keyboard input number and the random number seed, root for the Tree pointer, generate the specified node number of the binary Tree, for the use of other programs
Void wait () {
Printf (" please press any key to continue \ n \ n ");
getch();
}

Int main ()
{
Int a list (Max)={};//I look at the others don't need this definition and initialization of an array to elem array initialization only
//may be because I am useful to the parameter selection process in
The Tree=& amp; MYTREE;
MYTREE. Left=NULL;
MYTREE. Right=NULL;
Char choice;
While (1)
{
System (" CLS ");
Printf (" \ n \ n \ n \ n ");
Printf (" \ t \ n \ t binary tree operation ");
Printf (" \ \ t t======================================");
Printf (" \ n \ n ");
Printf (" \ \ t t 1: initialize \ n ");
Printf (" \ \ t t 2: displays \ n ");
Printf (" \ t \ t 0: exit \ n ");
Printf (" \ n ");
Printf (" \ t \ t please select: ");

Choice=getch ();
System (" CLS ");

The switch (choice)
{
Case '1' :
Init0 (list);
break;
Case '2' :
ShowBinTree (Tree);
break;
Case '0' :
exit(0);
}
}
}
Void BENULL BiTNode * (T)//to make son to null, the function in the front, there is no statement
{
T - & gt; Left=NULL;
T - & gt; Right=NULL;
}

Int init0 (int the list []) {//to create a binary tree, functions from the keyboard input number, and the random number seed, generate the specified number of data in the array elem,
//for the use of other programs!!!!!! End, 0 means data

int n;
//BiTNode * p, * q;
While (1)
{
Printf (" input element number (0-100) : ");
The scanf (" % d ", & amp; N);
If (n & gt;=0 & amp; & N & lt;
=100)break;
printf("\n");
}

Int I, value;
While (1)
{
Printf (" input random number seed (0-32767) : ");
The scanf (" % d ", & amp; I);
If (I & gt;=0 & amp; & i
=32767)break;
printf("\n");
}

/*//deleted from the linear table and release the original node, make its become empty table, not list don't need this steps operation
P=DLList;
While (p - & gt; Next!=NULL)
{
Q=p - & gt; next;
p-> Next=q - & gt; next;
Free (q);
} */

Srand (I);//the specified random number seed, the seeds of the same will produce the same data sequence
The rand ();

for (i=0; i {
The list [I]=rand () % 999 + 1;
Return the list [I];
}

/*//to insert length linear table a new node, not the list don't need this steps operation
It//but the steps and the binary tree is similar
for (int j=1; j<=length; J++)
{
P=new Node;
p-> Next=DLList - & gt; next;
DLList - & gt; Next=p;
p-> data=https://bbs.csdn.net/topics/rand () % 10000;
} */
/* else {//this is I find on the Internet to generate binary tree steps
T=new BiTNode;
T - & gt; data=https://bbs.csdn.net/topics/ch;
CreateBiTree (T - & gt; Left);
CreateBiTree (T - & gt; Right);
} */
}
/* T=new BiTNode;
T - & gt; data=https://bbs.csdn.net/topics/list [I];
Init1 (T - & gt; Left);
Init1 (T - & gt; Right); */
BiTNode * init1 (BiTNode * Tree) {

The int value.
BiTNode * T=new BiTNode;
T - & gt; data=https://bbs.csdn.net/topics/init0 (value);
Init1 (T - & gt; Left);
Init1 (T - & gt; Right);
}
Void Preorder BiTNode * (T)//first order output
{
If (T)
{
If (T - & gt; data=https://bbs.csdn.net/topics/=NULL);
The else {printf (" % d ", T - & gt; data); }/* */access nodes
Preorder (T - & gt; Left);
Preorder (T - & gt; Right);
}
}
Void Postorder BiTNode * (T)//in the sequence output
{
If (T)
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related