Professional Documents
Culture Documents
المرحلة :الثانية
المادة :هياكل بيانات
Write a program in C++ to implement stack by using array of
structures.
#include <iostream>
#include <stdlib.h>
///////////////////////////////////////////
#define max 6
struct stackst
int stackarray[max];
int top;
};
///////////////////////////////////////////
class myclass
public:
myclass();
virtual ~myclass();
};
///////////////////////////////////////////
int main()
myclass my0bj;
stackst s;
my0bj.push(&s,7);
my0bj.push(&s,14);
my0bj.push(&s,21);
my0bj.push(&s,28);
my0bj.push(&s,35);
my0bj.push(&s,42);
my0bj.push(&s,49);
for(int i=0;i=max;i++)
my0bj.pop(&s);
return(0);
}
///////////////////////////////////////////
s->top=-1;
if(s->top==max)
return(1);
else
return(0);
////////////////////
if(s->top==-1)
return(1);
else
return(0);
//////////////////
s->top++;
if(full(s))
cout<<"Stack full......"<<endl;
exit(0);
s->stackarray[s->top]=x;
//////////////////
if(empty(s))
cout<<"Stack empty......"<<endl;
exit(0);
return(s->stackarray[s->top--]);