Professional Documents
Culture Documents
Stack
Stack
Stack
:مميزاتها
dynamicحجمها ليس ثابتا 1.
Lifo: last in first outتعمل وفق 2.
Structنوعه البياني 3.
لديها مكتبة كامل في لغة السي ++اهمها الدوال التالية 4.
) (push
وضيفتها ادخال العناصر داخل المكدس
) (pop
وضيفتها اخراج اوحذف العناصر المكدس
) (empty
top=-1للتبين من ان
اي ان المكدس فارغ ام ال
) (full
للتبين من ان المكدس قد تخطى الحجم الذي افترضناه له ام ال
) (print
لطبع عناصر المكدس
++:وتاليا بناء هذه الدوال في لغة سي
>#include<iostream
#define size 10
;using namespace std
{struct stack
;int top
;]int item[size
; }s
while(choice!=4){
if(choice==1){
cout<<"how many ele to push "<<endl;
cin>>total;
if(choice==2){
cout<<"how many ele to pop"<<endl;
cin>>total;
for(int i=-1; i<total; i++)
pop(s);
}//end if ch 2
if(choice==3)
print(s);
cout<<"enter another choice"<<endl;
cin>>choice;
}//end while
return 0;
s.top=-1;
}//end of Maaaaaaaain
if(s.top == -1)
return 1;
else
return 0;
}
int full(stack s){
if(s.top==size-1)
return 1;
else
return 0;}
void push(stack &s,int num){
if(full(s))
cout<<"stack is full";
else
s.item[++(s.top)]=num ;
}
int pop(stack &s){
if (empty(s))
cout<<"stack is empty"<<endl;
else
return s.item[s.top--] ;
}