aminsaeedi
دوشنبه 27 آبان 1392, 22:43 عصر
دوستان من کد تابع push رو نوشتم ولی وقتی از تابع میام بیرون متغیر top به حالت اولیه برمی گرده
در حالی که این متغیر رو قبل از تابع اصلی معرفی کردم
int top;
int main()
{
top=-1;
int a=1;
int stack [n]={0};
while (a!=0)
{
cout << "Enter a Number!";
cin >> a;
push (stack,top,a);
cout << top << endl;
}
pop (stack,top);
return 0;
}
int push (int stack[n],int top, int x)
{
if (top==n-1)
return 0;
stack [++top]=x;
cout << stack[top++]<< endl;
return 1;
}
به نظرتون مشکل کجاست
در حالی که این متغیر رو قبل از تابع اصلی معرفی کردم
int top;
int main()
{
top=-1;
int a=1;
int stack [n]={0};
while (a!=0)
{
cout << "Enter a Number!";
cin >> a;
push (stack,top,a);
cout << top << endl;
}
pop (stack,top);
return 0;
}
int push (int stack[n],int top, int x)
{
if (top==n-1)
return 0;
stack [++top]=x;
cout << stack[top++]<< endl;
return 1;
}
به نظرتون مشکل کجاست