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

📄 linkedqueue.cpp

📁 利用链队列判断字符串的中心对称问题
💻 CPP
字号:
 //队列类的实现 

#include<iostream.h>
#include"LinkedQueue.h"
#include<stdlib.h>


template<class T>
LinkedQueue<T>::LinkedQueue(void)  //构造函数
{ 
	queue=new LinkedList<T>;
}


template<class T>
void LinkedQueue<T>::In(const T&item)  //入队列的函数
{   

	queue->SetPostion(queue->Size()-1);
	queue->InsertAfter(item);

}

template<class  T>
T LinkedQueue<T>::Out(void) //出对队列的函数
{
	T temp;
	if(!queue->Size())
	{
		cerr<<"out:underflowed!"<<endl;
	    exit(1);
	}
	queue->SetPostion(0);
	temp=queue->GeTData();
	queue->DeleteAt();
	return temp;
}

template<class T>
T LinkedQueue<T>::Front(void)
{
	//读队列头部的元素,判断是否非空
	//队列非空,返回队列头部的元素的值
	if(!queue->Size())
	{
		cerr<<"out:underflowed!"<<endl;
	    return NULL;
	}
	else
    return queue->GeTData();
}

template<class T>
 void LinkedQueue<T>::Clear(void) //清空队列的函数
{queue->Clear();}

template<class T>
int LinkedQueue<T>::Size(void) //获取队列大小的函数
{
	return queue->Size();
}

template<class T>
bool LinkedQueue<T>::IsEmpty(void)//判断队列大小的函数
{
	return queue->IsEmpty();
}


template<class T>
void LinkedQueue<T>::IsEquiralence()            //判断字符串是否对称函数的实现
{
   int i,j;
   char a[100];
   int k=Size();
   bool flag=false;  //判断栈对称的标志
  //读队列。
   if(!IsEmpty())//判链队列是否为中心对称
	{
		while(!k)
		a[i]=Out();
		for(i=0,j=k-1;i<=k/2 || j>=k/2;i++,j--)
		{
			if(a[i]==a[j])
			flag=true;      
			else
		{flag=false;break;}
		}
		if(flag==true) 
		cout<<"该字符串有中心对称关系"<<endl;
		else 
		cout<<"该字符串没有中心对称关系"<<endl;
	}
	else 
	   cout<<"你输入的字符串为空"<<endl;
  }

⌨️ 快捷键说明

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