請問以下交換二元樹節點的程式有甚麼錯?
我寫的交換二元樹節點的程式如下:
#include <iostream>
using namespace std;
struct node
{ int data;
struct node *left;
struct node *right;
};
void swaptree(struct node *t)
{
static int i=1;
struct node *p;
if ( t!=NULL)
{ p->left; t->left=t->right; t->right=p;
printf("第%d個節點的值為%d",i,t->data);
i++;
swaptree(t->left);
swaptree(t->right);}
}
int main(void) {
struct node *h1,*h2,item1,item2,item3,item4,item5;
h1=&item1; h2=&item1;
item1.data=1;item1.left=&item2;item1.right=&item3;
item2.data=2;item2.left=&item4;item2.right=&item5;
item3.data=3;item3.left=NULL;item3.right=NULL;
item4.data=4;item4.left=NULL;item4.right=NULL;
item5.data=5;item5.left=NULL;item5.right=NULL;
swaptree(h1);
return 0;
}