قمت بكتابة هذا البرنامج، ويتنفذ معي بس المشكلة أنه دالة pop المسؤولة عن الحذف ودالة top المسؤولة عن رأس المكدس فيهما مشكلة لم أعرفها!
مثلاً إذا أدخلت عددين إلى المكدس، وطلبت دالة pop عشان يحذف يقول لي أنه حذفها المفروض هنا أن يصبح لا يوجد في المكدس إلا عدد واحد ويكون هو top
بس لما أطلب دالة top يقول لي انه العدد اللي المفروض أنه أنحذف هو ال top، ولما أطلب دالة pop مرة ثانية يقول لي أنه حذف العدد اللي المفروض أني حذفته من قبل....... :blink:
الله يجزاكم خير ساعدوني، صدع راسي على كتابة هالبرنامج ووقفت عند المشكلة والتسليم المفروض اليوم أجلته إلى يوم الإربعاء
ساعدوني..:(
#include <iostream.h>
struct intstack{
int *stackary;
int count;
int stackmax;
int top;
};
intstack *mystack;
int i=1;
int value;
int *nada;
///////////////////////
intstack * createstack()
{
mystack =new intstack;
cout<<"\n\hi\n";
if(mystack==NULL)
return NULL;
else
{
cout<<"ooooo\n\n\n";
mystack->top=-1;
mystack->count=0;
mystack->stackmax=value;
mystack->stackary=new int;
if (mystack->stackary==NULL)
delete mystack;
return NULL;
}
return mystack;
}
////////////////////
int pushstack()
{
if (mystack->count==mystack->stackmax)
return 0;
else
{(mystack->count)++;
(mystack->top)++;
mystack->stackary[mystack->top]=value;
return 1;
}
}
///////////////////////////
int popstack ( )
{if (mystack->count==0)
return 0;
else
{*nada=mystack->stackary[mystack->top];
(mystack->count)--;
(mystack->top)--;
return 1;
}
}
//////////////////////
int stacktop()
{if (mystack->count>0)
{*nada=mystack->stackary[mystack->top];
return 1;
}
else
return 0;
}
////////////////////////
int emptystack()
{return (mystack->count==0);
}
////////////////////
int fullstack()
{
return (mystack->count==mystack->stackmax);
}
void main()
{
createstack();
cout<<"by\n";
while (i!=0)
{ cout<<"stack manipulation:\n\n";
cout<<"1-push\n";
cout<<"2-pop\n";
cout<<"3-top\n";
cout<<"4-empty\n";
cout<<"5-full\n";
cout<<"6-end\n";
cin>>i;
if(i==1)
{cout<<"value?\n";
cin>>value;
pushstack();
cout<<"vaue"<<value<<"pushed in\n";
}
else if(i==2)
{while(value==0)
{cout<<"\nstack is empty\n";
break;}
if(value!=0)
{
popstack();
cout<<"value"<<value<<"poped\n";
}
}
else if(i==3)
{ while(value==0)
{cout<<"\nstack is empty\n";
break;}
if(value!=0)
{
stacktop();
cout<<"value on the top"<<value<<"\n\n";
}
}
else if(i==4)
emptystack();
else if(i==5)
fullstack();
else
break;
}
}