السلام عليكم
اتوقع ان الخطا بـ while او ان محرري لايعمل جيدا
هذا الكود
#include<iostream>
using namespace std;
const int MAX=5;
void push(int stack[],int *top,int value)
{
if (*top < MAX-1)
{
*top=*top+1;
stack[*top]=value;
return;
}
else
cout<<"stack is full\n";
}
int pop(int stack[],int *top)
{
int value;
if (*top > -1)
{
value=stack[*top];
*top=*top-1;
return value;
}
else
return -1;
}
void main(){
int stack[MAX],top=-1,value,answer,choice;
cout<<"1. to push element\n" <<"2. to pop element\n"<<"3. to counting list\n"
<<"4. to print elements\n"<<"5. to return top\n"<<"6. to ensure if stack is full\n"
<<"7. to ensure if stack is empty\n";
cout<<"want to try (y/n)\n"; cin>>answer;
while(answer=='Y'||answer=='y') {
cout<<"Enter your choise:\n"; cin>>choice;
switch(choice) {
case 1: cout<<"Enter the value to push:\n";
cin>>value;
push(stack,&top,value);
break;
case 2: value=pop(stack,&top);
if(value!=-1)
cout<<"the value poped is "<<value<<endl;
else
cout<<"stack is empty\n";
break;
default:cout<<"invalide choise\n";
}
cout<<"more ?(y/n)\n"; cin>>answer;
}/*end while */
}
