Добавил:
Upload
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:SIAOD / Стек и очередь / STEK
.CPP#include <iostream.h>
#include <conio.h>
class stek{
private:
struct list{
int num;
list *next;
};
list *head;
public:
stek();
void pop();
void push(int num);
int output();
~stek();
};
void main(){
stek *object=new stek();
clrscr();
int chose;
do{
clrscr();
cout<<" 1-pop"<<endl;
cout<<" 2-push"<<endl;
cout<<"<1-Exit"<<endl;
cout<<"chose=";
cin>>chose;
if(chose == 1){
if(object->output() == -1)
cout<<"Your stek is empty."<<endl;
object->pop();
if(object->output() == -1)
cout<<"Your stek is empty."<<endl;
getch();
}
else if(chose == 2){
int num;
cout<<"num=";
cin>>num;
object->push(num);
}
}while(chose>0);
delete object;
}
stek::stek(){
head=NULL;
}
stek::~stek(){
list *p;
while(head!=NULL){
p=head;
head=head->next;
delete p;
}
}
void stek::push(int num){
list *temp=new list;
temp->num=num;
temp->next=head;
head=temp;
}
int stek::output(){
if(head == NULL)
return -1;
list *p=head;
while(p!=NULL){
cout<<p->num<<" ";
p=p->next;
}
cout<<endl;
return 1;
}
void stek::pop(){
if(head==NULL)
return;
list *p;
p=head;
int num;
num=p->num;
head=head->next;
delete p;
}
Соседние файлы в папке Стек и очередь