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

📄 pex5_6.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 CPP
字号:
#include <iostream.h>
#pragma hdrstop

typedef char DataType;

#include "astack.h"
#include "aqueue.h"

void main (void)
{
	// S holds non-blank chars of the string in reverse
	Stack S;
	// Q holds non-blank chars of the string
	Queue Q;
	// line contains possible palindrome, p scans line
	char line[128], *p = line;
	int ispalindrome = 1;

	cout << "Enter a possible palindrome: ";
	cin.getline(line,128,'\n');
	
	// scan the string, pushing each non-blank character onto Q
	// and inserting each into Q
	while(*p != NULL)
	{
		if (*p != ' ')
		{
			S.Push(*p);
			Q.QInsert(*p);
		}
		p++;
	}

	// pop stack and delete from the queue. if the two
	// characters are not equal, the string is not a palindrome
	while(!S.StackEmpty())
		if (S.Pop() != Q.QDelete())
		{
			ispalindrome = 0;
			break;
		}

	if (ispalindrome)
		cout << '"' << line << '"' << " is a palindrome."
			 << endl;
	else
		cout << '"' << line << '"' << " is not a palindrome."
			 << endl;
}

/*
<Run #1>

Enter a possible palindrome: madam im adam
"madam im adam" is a palindrome.

<Run #2>

Enter a possible palindrome: confer
"confer" is not a palindrome.
*/	 

⌨️ 快捷键说明

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