typedef struct BITNODE
{
char value;
Bitnode *lchild,*rchild;
}bitnode,*bitree;
void Creattree (bitnode* &root,char *pre,int l1,int r1,char *in,int l2,int R2);
/* What does *& stand for? Https://zhidao.baidu.com/question/2266744263935050308.html
This is the syntax for C + +,& The reference argument in the formal parameter,
Lnode * &LST; The Lnode * is a whole, indicating that the variable type is a Lnode class pointer, and the & in &lst indicates the reference argument, which is an alias representing the argument.
Standard C does not support this notation.
Ask
& not address characters? What does the reference parameter mean?
Chase Answer
& in the variable definition area, indicating the reference, pay attention to its usage,
& in the variable operation area, which represents the fetch address character, such as:
int x=10, *p=&x; Here & function on X, is to take the address character
int &x; Reference is a new feature introduced by C + +, you do not want to learn C + +, the above code you do not understand. The & Here is quoted. In general, this form will appear in the formal parameter.
Lnode * &LST; The Lnode * is a whole, indicating that the variable type is a Lnode class pointer, and the & in &lst indicates the reference argument, which is an alias representing the argument. Manipulating reference variables is equivalent to manipulating real parametric
*/
Binary tree using pre-order and middle order (source code):
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- using namespace std;;
- const int n=;
- typedef struct bitnode
- {
- char value;
- Bitnode *lchild,*rchild;
- }bitnode,*bitree;
- / * What does *& stand for?
- This is the syntax for C + +,& The reference argument in the formal parameter,
- Lnode * &LST; Lnode * is a whole, indicating that the variable type is a Lnode class pointer, and that the & in &lst indicates the reference argument, which is an alias representing the argument.
- standard C does not support this notation.
- questioning
- & not address characters? What does the reference parameter mean?
- Chase Answer
- & in the variable definition area, indicating the reference, pay attention to its usage,
- & in the variable operation area, which represents the fetch address character, such as:
- int x=10, *p=&x;//here & function on X, is take address character
- int &x;//reference is a new feature introduced by C + +, you do not learn C + +, the above code you do not understand. The & Here is quoted. In general, this form will appear in the formal parameter.
- Lnode * &LST; Lnode * is a whole, indicating that the variable type is a Lnode class pointer, and that the & in &lst indicates the reference argument, which is an alias representing the argument. Manipulating reference variables is equivalent to manipulating real parametric
- */
- void creattree(bitnode* &root,char *pre,int L1,int R1,char *in,int L2, int R2)
- {
- if (L1<=R1&&L2<=R2)
- {
- int KEY=PRE[L1];
- int midindex=-1;
- For (int i=l2;i<=r2;i++)
- {
- if (in[i]==key)
- {
- Midindex=i;
- Break ;
- }
- }
- root= (Bitnode *)malloc (sizeof (Bitnode));
- root->value=key;
- root->lchild=NULL;
- root->rchild=NULL;
- int llen=midindex-l2;
- Creattree (Root->lchild, Pre, l1+1, L1+llen, in, L2, Midindex-1);
- Creattree (Root->rchild, Pre, l1+llen+1, R1, in, midindex+1, r2);
- }
- }
- void postordertraverse(bitnode *&root)
- {
- if (root->lchild)
- Postordertraverse (Root->lchild);
- if (root->rchild)
- Postordertraverse (Root->rchild);
- printf ("%c", Root->value);
- }
- int main()
- {
- Char pre[n],in[n];
- while (scanf ("%s", pre)!=eof)
- {
- scanf ("%s", in);
- int len1=strlen (pre);
- int len2=strlen (in);
- Bitnode *root=NULL;
- Creattree (Root,pre,0,len1-1,in,0,len2-1);
- Postordertraverse (root);
- printf ("\ n");
- }
- return 0;
- }
What does "*&" mean in C + + function parameters? ”