关于语法方面的问题
大家好,我写了一次程序,名字是3_7.cpp,代码如下:
#include<iostream>using namespace std;typedef char ElemType;struct GLNode{ bool tag; union{ ElemType data; GLNode* sublist; }; GLNode* next;};void Create1(GLNode*& GL, char* a){ if(NULL == a) { return; } if('\0' == *a) return; if('(' == *a) { GL->tag = true; Create1(GL->sublist, ++a); } else if('#' == *a) { GL = NULL; } else { GL->tag = false; GL->data = *a; } ++a; if(*a == ',') Create1(GL->next), ++a; else if(*a == ')' || *a == ';') else if(*a == ')' || *a == ';') GL->next = NULL;}void Print(GLNode* GL){ if(GL->tag) { cout << '('; if(GL->sublist == NULL) cout << '#'; else Print(GL->sublist); cout << ')'; } else cout << GL->data; if(GL->next != NULL) { cout << ','; Print(GL->next); }}int main(){ GLNode* GL = NULL; char str[] = "(a,(#),b,c(d,(e)));"; Create1(GL, str); Print(GL); return 0;}