السلام عليكم ورحمة الله وبركاته ..
عندي بروجكت عن المكدسات ..
والواجب عبارة عن عمل برنامج ، المستخدم يدخل فيه عدد من الألوان : احمر - اصفر - ازرق .... الى حد 15 لون
بعد كدا يختار لون من دي الألوان عشان يشيلها من المكدسه ،
وارجع المكدسه زي ماكانت بس من غير اللون اللي اختار المستخدم انه يحذفه !!
مثال :
Suppose you place ccolors in this order: R R Y B G R B Y B G Y R B B G
Then the stack would look like this:
R
R
Y
B
G
R
B
Y
B
G
Y
R
B
B
G (top of stack)
If you asked to remove all green the resulting stack would be:
R
R
Y
B
R
B
Y
B
Y
R
B
B(top of stack)
-----------------
أنا عملت كود ، لكن مو راضي يزبط معايا أبداً للأسف ، وماني عارفة اللي عملته صح او خطأ !!
فهل في أحد يفيدني فين خطأي وايش ممكن أقدر أعمل ؟؟
#include <iostream>
#include <fstream>
#include <cstdlib>
//#include <string>
//#include <stack>
using namespace std;
const char maxstack = 15;
class stack_type // declaration of class//
{
public:
void clear_stack(); //member functions//
bool empty_stack(); // of class stack_type//
bool full_stack();
void push(char color);
void pop(char& color);
// int stack[maxstack];
int top,size;
};
//---------------------------------------------------------------------
int main()
{
stack_type s1,s2;
int i;
char candy,rcolor;
s1.clear_stack();
s2.clear_stack();
//stack<string> instack, outstack;
int n;
//string a, b;
//cin>>n;
cout << " Enter some coolor : \n";
cin>>candy;
for (i=0; i<n; i++)
{
s1.push(candy);
}
cout<<" what Color do you wish to remove? = \n";
cin>>rcolor;
while (s1.size())
{
if (s1.top!=rcolor)
{
s2.push(s1.top);
s1.pop(candy);
}
}
while (s2.size())
{
cout<<s2.top<<endl;
s2.pop(candy);
}
system ("pause");
return 0;
}
//----------------------------------------------------------------------
void stack_type::clear_stack()
{
top = 0;
}
//----------------------------------------------------------------------
bool stack_type::empty_stack()
{
if (top==0)
return true;
else
return false;
}
//----------------------------------------------------------------------
bool stack_type::full_stack()
{
if (top==maxstack-1)
return true;
else
return false;
}
//----------------------------------------------------------------------
void stack_type::push(char color)
{
top = top + 1;
stack[top]=color;
}
//----------------------------------------------------------------------
void stack_type::pop(char& color)
{
color = stack[top];
top = top - 1;
}