لسلام عليكم ورحمه الله وبركاته..
حاولت في حل هذا السؤال
وقد نجحت في حل سؤال يشابهه قليلا في السابق. بفضل الله ثم الاعضاء الصبورين معي :)
Write a program that reads a line of text, changes each uppercase letter to lowercase, and places each letter both in a queue and onto a stack
the program should then verifty whether the line of text is a palindrome
حقا لم اعرف كيف اقسم كلمه من نوع سترينغ الى رموز (كركتر)
لم يقم السؤال بطلب مني انه اكتبه الكود كفنكشن او ممبر فنكشن
لكنني حاولت عليه كنون ممبر فنكشن :)
مثال:
ادخلت اسم رادار لأتأكد ان كانت palindrome ام لا
اولا اقوم بتجزئة الكلمه المعرفه سابقا من نوع سترينغ الى كركتر
ثم اقوم بوضع كل كركتر في stack و كذلك في queue
ثم اقوم بالمقارنه palindrome
#include <iostream>
#include<string>
using namespace std;
class queue
{
private:
char queueFront;
char queueRear;
int maxQueueSizs;
int count;
char *list;
public:
bool isEmptyQueue()
{
return(count==0);
}
bool isFullQueue()
{
return(count == maxQueueSizs);
}
void initializeQueue()
{
queueFront=0;
queueRear=maxQueueSizs-1;
count=0;
}
char front()
{
return list[queueFront];
}
char back()
{
return list[queueRear];
}
void addQueue(const char& newElemnt)
{
if(! isFullQueue())
{
queueRear=(queueRear+1)%maxQueueSizs;
count ++;
list[queueRear]=newElemnt;
}
else
cout<<" can not add to a full queue."<<endl;
}
void deleteQueue()
{
if(! isEmptyQueue())
{
count--;
queueFront=(queueFront+1)%maxQueueSizs;
}
else
cout<<"can not remove from empty queue."<<endl;
}
};
class stackType
{
private:
char *list;
int stackTop;
int maxSize;
public:
stackType( int size=100)
{
if(size<=100)
maxSize=100;
else
maxSize=size;
stackTop=0;
list=new int[maxSize];
}
int isEmpty()
{
bool found=true;
if(stackTop==0)
return 1;
else
return 0;
}
int isFull()
{
bool found=true;
if(stackTop==maxSize)
return 1;
else
return 0;
}
char push(char item)
{
if(isFull())
cout<<"full stack";
else
{
list[stackTop]=item;
stackTop++;
}
}
void pop()
{
if(isEmpty())
cout<<"is Empty";
else
stackTop--;
}
char Top()
{
if(stackTop !=0)
return list [stackTop-1];
else
return -1;
}
};
void palindrome(string word,int length)
{
bool found;
stackType s;
queue s1;
for(int i=0;i<length; i++)
{
s.push(word);
s1.addQueue(word);
}
while(!s.isEmpty())
{
if(s.Top()!=s1.front())
{
found = false;
break;
}
else
{
s.pop();
s1.deleteQueue();
found= true;
}
}// end foor loop
if( true)
cout << "It is a palindrome";
else
cout << "It is a not palindrome";
} //end function
int main()
{
string word;
int length;
cout<<"enter length of the word."<<endl;
cin>>length;
cout<<"please enter your string word"<<endl;
cin>>word;
palindrome(word,length);
return 0;
}

