📄 stacklist.cpp
字号:
//in barname stack ra bevasileye linklist ejra mikonad
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class Stacklist;
class node
{
friend class Stacklist;
node(int x){data=x;}
node(){}
private:
int data;
node *next;
node *prev;
};
//****************************************************************
class Stacklist
{
public:
Stacklist();
void delet();
void add();
void show();
private:
node *first;
node *last ;
};
//****************************************************************
Stacklist::Stacklist()
{
first=last=0;
}
//****************************************************************
void Stacklist::add()
{
int x;
cout<<"Enter a number: "<<endl;
cin>>x;
node *help1=new node;
help1->next=NULL;
help1->data=x;
if(first==0)
{
first=last=help1;
first->prev=NULL;//agar in khat nabashad dar methode show khate(cout<<help->data<<" ";) qalat migirad
}
else
{
last->next=help1;
help1->prev=last;
last=help1;
}
}
//****************************************************************
void Stacklist::delet()
{ int a;
node *temp=new node;
temp=last->prev;
a=last->data;
delete last;
last=temp;
last->next=NULL;
cout<<"element Deleted= "<<a<<endl;
}
//****************************************************************
void Stacklist::show()
{
node *help;
help=last;
while(help )
{
cout<<help->data<<" ";
help=help->prev;
}
cout<<endl;
}
//****************************************************************
int menu();
int main()
{
Stacklist li;
for(;;)
{
switch(menu())
{
case 1:li.add();break;
case 2:li.delet();break;
case 3:li.show();break;
case 4:exit(1);
}
}
getch();
return 0;
}
//****************************************************************
int menu()
{
int choice;
cout<<"1.Enter a student : "<<endl
<<"2.Delete a student : "<<endl
<<"3.Display stack : "<<endl
<<"4.End of rogram : "<<endl;
cout<<"Enter yoUr select(1-4): ";
cin>>choice;
return choice;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -