main.cpp

来自「易学c++程序实例 本章主要讲述一些学习程序设计前需要了解的一些知识和一些学习」· C++ 代码 · 共 79 行

CPP
79
字号
#include "iostream.h"
struct node
{
	char operation;
	node * next;
};
node * create();
void showList(node *head);
void destory(node * &head);
void main()
{
	node *head;
	head=create();
	showList(head);
	destory(head);
}
node * create()
{
	node *head=NULL;
	node *pEnd=head;
	node *pGuard;
	node *pS;
	char temp;
	cout <<"请输入指令:" <<endl;
	do
	{
		cin >>temp;
		if (temp!='#')
		{
			if (temp!='$')
			{
				pS=new node;
				pS->operation=temp;
				pS->next=NULL;
				if (head==NULL)
				{
					head=pS;
				}
				else
				{
					pEnd->next=pS;
				}
				pGuard=pEnd;
				pEnd=pS;
			}
			else
			{
				pGuard->next=NULL;
				delete pEnd;
				pEnd=pGuard;
				for (pGuard=head;pGuard->next->next!=NULL;pGuard=pGuard->next);
			}				
		}
	}while (temp!='#');
	return head;

}
void showList(node *head)
{
	node *pRead=head;
	cout <<"用户的实际操作是:" <<endl;
	while (pRead!=NULL)
	{
		cout <<pRead->operation;
		pRead=pRead->next;
	}
	cout <<endl;
}
void destory(node * &head)
{
	node *p;
	while (head!=NULL)
	{
		p=head;
		head=head->next;
		delete p;
	}
}

⌨️ 快捷键说明

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