main.cpp

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

CPP
69
字号
#include <iostream>
using namespace std;
struct node
{
	char person;
	node * next;
};
node * create();
void destory(node * &head);
int main()
{
	node *head;
	head=create();
	destory(head);
	return 0;
}
node * create()
{
	int time=0;
	node *head=NULL;
	node *pEnd=head;
	node *pGuard;
	node *pS;
	char temp;
	cout <<"请输入序列:";
	do
	{
		cin >>temp;
		if (temp!='#')
		{
			if (temp!='$')
			{
				time++;
				pS=new node;
				pS->person=temp;
				pS->next=NULL;
				if (head==NULL)
				{
					head=pS;
					pGuard=head;
				}
				else
				{
					pEnd->next=pS;
				}
				pEnd=pS;
			}
			else
			{
				head=head->next;
				cout <<pGuard->person <<' ' <<time <<'s' <<endl;
				delete pGuard;
				pGuard=head;
			}				
		}
	}while (temp!='#');
	return head;
}
void destory(node * &head)
{
	node *p;
	while (head!=NULL)
	{
		p=head;
		head=head->next;
		delete p;
	}
}

⌨️ 快捷键说明

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