⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 广义表.txt

📁 方便快捷地实现目标的查找
💻 TXT
字号:
#include "stdafx.h"
#include "iostream.h"

typedef enum{ATOM,LIST}ElemTag;
typedef struct GLNode{
	ElemTag tag;
	union{
		int atom;
		struct GLNode *hp;
	};
	struct GLNode *tp;
} *GList;
void initGList(GList &L)
{L=new(GLNode);
 L->tag=LIST;
 L->hp=L->tp=NULL;
}
GList buildGList(GList &L1)
{
 initGList(L1);
 L1->hp=new(GLNode);
 for(int i=0;i<3;i++)
 {
 cout<<"原子则输入0而列表则输入1:";
 int h;
 cin>>h;
 if(h==0) 
 {
 L1->hp->tag=ATOM;
 int k;
 cout<<"请输入原子k:";
 cin>>k;
 L1->hp->atom=k;
 
 L1->hp=L1->hp->tp;
 L1->hp=new(GLNode);
 }
 else if(h==1)
 {
  L1->hp->tag=LIST;
  L1->hp->hp=new(GLNode);
  L1->hp->hp->tag=ATOM;
  int n;
  cout<<"请输入列表原子n:";
  cin>>n;
  L1->hp->hp->atom=n;
  L1->hp->hp->tp=NULL;
  L1->hp=L1->hp->tp;
  L1->hp=new(GLNode);
 }
 else cout<<"输入错误!!!";
 }
 L1->hp=NULL; 
 return L1;
}
void GetHead(GList &L3)
{
 if(L3->hp->tag==ATOM) cout<<L3->hp->atom;
 else cout<<"("<<L3->hp->hp->atom<<")";

}

int main(int argc, char* argv[])
{GList L2;
 buildGList(L2);
 GetHead(L2);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -