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

📄 6_57.cpp

📁 《c++程序设计技能百练》源代码,内有99个实例。
💻 CPP
字号:
#include<iostream.h>
#include<string.h>
struct sqstack
{
	char data;
	sqstack* top;
};
class stack
{
	sqstack * st;
public:
	void init()
	{
		st=NULL;
	}
	void push(char );
	char pop();
};
void stack::push(char k)
{
	sqstack * newst=new sqstack;
	newst->data=k;
	newst->top=st;
	st=newst;
}
char stack::pop()
{
	char value;
	sqstack* t;
	value=st->data;
	t=st;
	st=st->top;
	delete t;
	return value;
}

struct list
{
	int data;
	list *next;
};
class queue
{
	list *head,*tail;
public:
	void init()
	{
		head=tail=NULL;
	}
	void Inq(int x);
	int Outq();
};
void queue::Inq(int x)
{
	list *newnd=new list;
	newnd->data=x;
	newnd->next=NULL;
	if(tail==NULL)
		head=tail=newnd;
	else
	{
		tail->next=newnd;
		tail=newnd;
	}
}
int queue::Outq()
{
	list *temp;
	int value;
	value=head->data;
	temp=head;
	head=head->next;
	delete temp;
	return value;
}
void main()
{
	stack A;
    A.init();
	queue B;
    B.init();
	char arr[80];
	cout<<"请输入字符序列,回车键结束:"<<endl;
	cin.getline(arr,80);
	int h=strlen(arr);
	for (int i=0;i<h;i++)
	{
		A.push(arr[i]);
		B.Inq(arr[i]);
	}
	for(i=0;i<h;i++)
	{
		if(A.pop()!=B.Outq())
		{
			cout<<"你所输入的字符序列不是回文!"<<endl;
		    return;
		}
	}
	cout<<"你所输入的字符序列是回文!"<<endl;
}

⌨️ 快捷键说明

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