数据结构求二叉树的宽度问题

小白刚学..可能错误有点多,求大神解答

错误提示:
error C2146: syntax error : missing ';' before identifier 'A'
error C2501: 'St' : missing storage-class or type specifiers
fatal error C1004: unexpected end of file found

求二叉树宽度.exe - 1 error(s), 0 warning(s)

#include
#include
#define maxsize 20

St A[maxsize];

int L=1;//记录层数
int i=0;
void width(BTNode *p);
BTNode *CreateBiTree();

void main()
{
int j,k=0;
int max=0;
BiTree T;
T = CreateBiTree();//建立
width(T);

    for(j=0;j<=i;j++)
    {
      if(A[j].level==A[j+1].level)
      {
        ++k;
            max=(k>max?k:max);
      }
      else
              k=1;
    }
    printf("%d\n",max);

}

typedef struct BTNode{
int data;
struct BTNode *lchild,*rchild;
}BTNode;

//先序建立二叉树
BTNode *CreateBiTree(){
char ch;
BTNode *T;
scanf("%c",&ch);
if(ch=='#')T=NULL;
else{
T = (BTNode *)malloc(sizeof(BTNode));
T->data = ch;
T->lchild = CreateBiTree();
T->rchild = CreateBiTree();
}
return T;//返回根节点
}

typedef struct
{
BTNode *q;
int level;
}St;

void width(BTNode *p)
{

A[i].q=p;
A[i].level=L;
++i;
++L;
width(p->lchild);
width(p->rchild);
--L;

}

C语言要求先定义后使用,所以要把函数的定义和结构体的定义放在前面。

不考虑程序本身的对错,可以编译运行的修改如下:

#include <stdio.h>
#include <malloc.h>
#define maxsize 20

typedef struct BTNode{
int data;
struct BTNode *lchild,*rchild;
}BTNode;

typedef struct
{
  BTNode *q;
  int level;
}St;

St A[maxsize];

int L=1;//记录层数
int i=0;
void width(BTNode *p);
BTNode *CreateBiTree();


//先序建立二叉树
BTNode *CreateBiTree(){
char ch;
BTNode *T;
scanf("%c",&ch);
if(ch=='#')T=NULL;
else{
T = (BTNode *)malloc(sizeof(BTNode));
T->data = ch;
T->lchild = CreateBiTree();
T->rchild = CreateBiTree();
}
return T;//返回根节点
}

void width(BTNode *p)
{

  A[i].q=p;
  A[i].level=L;
  ++i;
  ++L;
  width(p->lchild);
  width(p->rchild);
  --L;

}

int main()
{
   int j,k=0;
        int max=0;
  BTNode * T;
  T = CreateBiTree();//建立
  width(T);


        for(j=0;j<=i;j++)
        {
          if(A[j].level==A[j+1].level)
          {
            ++k;
                max=(k>max?k:max);
          }
          else
                  k=1;
        }
        printf("%d\n",max);

}