أرجوكم اريد شرح مبسط لهذه الأكواد في ال stack وهي بلغة ال ++c
#include<iostream>
#include<process.h>
#include <conio.h>
using namespace std;
#define size 20;
class stack
{
int a[size];
int tos;
public:
stack();
void push(int);
int pop();
int isimpty();
int isfull();
void topelem();
void display();
};
stack::stack()
{
tos=0;
}
int stack::isimpty()
{
return(tos==0?1:0);
}
int stack::isfull()
{
return(tos==size?1:0);
}
void stack::push(int i)
{
if(!isfull())
{
a[tos]=i;
tos++;
}
else
cout<<"stack overflow !possible data loss!";
}
}
int stack::pop();
{
if(!isempty())
{
{
int data=a[tos];
a[tos]=Null;
tos--;
}
return(a[tos])
}
else
{
cout<<"stack is empty!what to pop....!";
}
void stack::display()
{
int j=0;
int elem=0;
while(tos!j)
{
elem=a[j];
cout<<"the element in the location of ["<<j<<"] is "<<elem<<endl;
++j;
}
}
return0;
}
void stack ::topelem()
{
cout<<"the most top element is"<<a[tos-1]<<endl;
}
void main()
{
stack s;
int ch;
int ch=1,num;
while(ch!=0)
{
cout<<"stack operations main menu 1.push 2.pop 3.isempty 4.isfull 5.display 6.topelem 0.exit";
switch(ch)
{
case 0:
exit(1);
case 1:
cout<<"enter the num to push";
cin>>num;
s.push(num);
break;
case 2:
cout<<" num popped from the stack is : ";
s.pop();
break;
case 3:
(s.isimpty())?(cou<<"stack is empty."):(cout<<"stack is notempty.");
break;
case 4:
(s.isfull())?(cou<<"stack is empty."):(cout<<"stack is notfull.");
break;
case 5:
cout<<"enter the num to push";
s.display();
break;
case 6:
s.topelem();
break;
default:
cout<<"illegal option .please try again";
}
getch();
}
}
