هيدا سؤال اول شي
بانوا نكتبPALINDROME بواسطة لغة السي بلس بلس
ونكتبوا باستخدام Stack application
والبرنامج بيحكي
• Write a program to read a string and determine if the string is a palindrome. A palindrome is a string which is the same whether the characters are read from left to right or from right to left. For example "radar" , "deed", and "able was I ere I saw elba" are all examples of palindromes.
• The palindrome algorithm is simple: compare the reverse of the string with the original string. If they are the same, the string is a palindrome.
• Use a stack ADT and any other structured data type with it as array of characters
• Use Two Files a .h and a .cpp File
وهادا تم الاجابة عليه واجابته هايتها
اقتباسملف السي بلس بلس#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include"pal.h"
void main()
{
clrscr();
stack st;
char arr[30]="";
cout<<"please enter a string";
cin>>arr;
int x=0;
while (arr[x])
x++;
int i;
for (i=0;i<x;i++)
st.push(arr);
for (int a=0;a<x;a++){
if(arr[a]==st.top()) {
st.pop();
continue; }
else
break;}
if(a==x)
cout <<"paledrom";
else
cout <<"not paledrom";
getch();
}
//End main
ملف .h
اقتباس#include<iostream.h>#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
stack::stack()
{
mytop=-1;
}
int stack::empty()
{
return (mytop==-1);
}
void stack::push (stack_element &value)
{
if (mytop < size-1)
{
mytop++;
myarray[mytop]=value;
}
}
void stack::pop()
{
if (mytop != -1)
mytop --;
else
cerr<<"stack is empty";
}
stack_element stack::top()
{
if (mytop !=-1)
return (myarray[mytop]);
else
{
cerr<<"stack is empty";
return -1;
}
}
void stack::display()
{
for(int i=mytop ; i>= 0; i--)
cout<< myarray ;
}
const int size=20;
typedef int stack_element;
class stack
{
private:
int mytop;
stack_element myarray ;
public:
stack();
int empty();
void push(stack_element &value);
void pop();
stack_element top();
void display();
};
وبدنا بنفس البرنامج بلغة السي بلس بلس
ولكن باستخدام Queue application
As You Worked in assignment 2 , Write a palindrome program , But this Time Use Queue and Stack ADT's in your program
• Use Two Files a .h and a .cpp File
لو سمحتم بس المساعدة باستخدام الـــQueue application
بس هادا السؤال
ضروري الله يخليكم
والله كتير محتاجها
