sms.cpp

来自「C++编写的一个模拟短信接受予删除短信」· C++ 代码 · 共 104 行

CPP
104
字号
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <conio.h>
#include "sms.h"
using namespace std;

int main()
{
	int  event_num;

	cin>>event_num;//输入事件个数

	LList*	L=ListInit( 1 );//构造一个空的线性表

	int i=0,swch;

	Rank n=0;

	string event_type,tmp;

	LValueType message;

	for (;i<event_num;i++)

	{

		cin>>event_type;//输入事件类型

		getline(cin,tmp,'\"');//将前面的引号去掉

		cin.getline(message,200,'\"');//输入短信,遇到后一个引号删除
	
		if (event_type=="NEW")

			swch=0;

		else if(event_type=="DELETE")swch=1;

		else swch=2;

		switch (swch)

		{

		case(0):

			L=ListInsert(L,message);//插入短信

			n++;	

			break;

		case(1):

			L=ListDelete(L,message);//删除短信

			n--;

			break;

		default:continue;

		}

	}	

	Position p=ListNext(L->header);

	if (L->length)

	{
	
		cout<<L->length<<endl;//输出线性表长度

		while (p)//如果节点不是尾节点则进入循环

		{

			if (p->Empty==TRUE)

			{
				p=ListNext(p);continue;//如果p所指节点指示为空,则继续循环

			}

			for (int q=0 ;p->value[q]!='\0';q++ )

				cout<<p->value[ q ] <<endl;////如果p所指节点指示不为空,则输出节点的数据

			p=ListNext(p);

		}

	}

	else cout<<L->length<<endl;//如果节点是尾节点则输出线性表长度

	ListDestroy(L);//销毁线性表

	return 0;

}

⌨️ 快捷键说明

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