数据结构:
栈是允许在同一端进行插入和删除操作的特殊线性表。允许进行插入和删除操作的一端称为栈顶(top),另一端为栈底(bottom);栈底固定,而栈顶浮动;栈中元素个数为零时称为空栈。插入一般称为进栈(PUSH),删除则称为退栈(POP)。栈也称为后进先出表。
操作系统:
由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈
栈使用的是一级缓存, 他们通常都是被调用时处于存储空间中,调用完毕立即释放。
具体操作有:初始化 判断栈满 判断栈空 push pop 读取栈顶
using namespace std;
#define TRUE 1
#define FALSE 0
#define Stack_Size 50
#define StackElementType char
/*顺序栈*/
typedef struct
{
StackElementType elem[Stack_Size]; /*用来存放栈中元素的一维数组*/
int top; /*用来存放栈顶元素的下标,top为-1表示空栈*/
}SeqStack;
/*初始化*/
void InitStack(SeqStack *S)
{
/*构造一个空栈S*/
S->top = -1;
}
/*判栈空*/
int IsEmpty(SeqStack *S) /*判断栈S为空栈时返回值为真,反之为假*/
{
return(S->top==-1?TRUE:FALSE);
}
/*判栈满*/
int IsFull(SeqStack *S) /*判断栈S为满栈时返回值为真,反之为假*/
{
return(S->top==Stack_Size-1?TRUE:FALSE);
}
int Push(SeqStack *S,StackElementType x)
{
if(S->top==Stack_Size-1)
return(FALSE); /*栈已满*/
S->top++;
S->elem[S->top] = x;
return(TRUE);
}
int Pop(SeqStack *S,StackElementType *x)
{
/* 将栈S的栈顶元素弹出,放到x所指的存储空间中 */
if(S->top == -1) /*栈为空*/
return(FALSE);
else
{
*x = S->elem[S->top];
S->top–; /* 修改栈顶指针 */
return(TRUE);
}
}
/*读栈顶元素。*/
int GetTop(SeqStack *S,StackElementType *x)
{
/* 读取栈S的栈顶元素,放到x所指的存储空间中,但栈顶指针保持不变 */
if(S->top == -1) /*栈为空*/
return(FALSE);
else
{
*x = S->elem[S->top];
return(TRUE);
}
}
int main()
{
SeqStack T;
InitStack (&T);
StackElementType x,y;
x='@';
if(Push(&T,x))
cout<<"储存成功!"<<endl;
else
cout<<"入栈失败!"<<endl;
cout<<"目前T.top="<<T.top<<"读取后="<<endl;
if(GetTop(&T,&x))
cout<<T.top<<endl;
else
cout<<"读栈失败!"<<endl;
if(Pop(&T,&y))
cout<<y<<endl;
else
cout<<"出栈失败!"<<endl;
return 0;
}
波比源码 » 栈操作之顺序栈
levaquin 250mg pills order levaquin 250mg pill
spironolactone buy online spironolactone 25mg drug diflucan price
lamotrigine 200mg sale vermox pill tretinoin cream cheap
buy anastrozole 1mg online Buy viagra lowest price buy sildenafil 100mg generic
modafinil 200mg without prescription modafinil 200mg brand buy diamox 250 mg online cheap
cost terazosin 5mg buy sulfasalazine 500 mg generic sulfasalazine 500 mg drug
purchase nootropil online cheap order sildenafil 50mg online cheap order sildenafil
itraconazole 100 mg usa sporanox 100 mg cost order tindamax 300mg without prescription
linezolid 600mg pills play roulette free for fun slots games
cheap cialis online buy tadalafil 20mg for sale viagra pills 200mg
xenical without prescription buy orlistat 120mg online cheap order acyclovir 800mg generic
play roulette for free poker game chumba casino
cialis india cheap tadalafil 5mg buy generic ciprofloxacin
diflucan us sildenafil 150mg for sale buy viagra 100mg online cheap
online black jack casino arizona buy cialis 20mg pill
viagra usa sildenafil dosage tadalafil online order
casino real money cialis 40mg cost cost cialis
texas poker online play blackjack casino games online order provigil 200mg pill
prednisone 5mg pill mebendazole 100mg usa order vermox 100mg for sale
tretinoin uk buy tretinoin cream without prescription avana 100mg cheap
tadacip 10mg sale order tadalafil without prescription buy indomethacin 75mg sale
order actos 15mg generic pioglitazone 15mg price order viagra 100mg pills
ivermectin without a doctor prescription buy dapsone for sale dapsone uk
cost ramipril 10mg order glimepiride 4mg for sale etoricoxib over the counter
how to write a hiring letter order leflunomide 10mg generic sulfasalazine order online
doxycycline 100mg cost order albuterol online cheap cleocin 300mg brand
mesalamine 800mg us oral irbesartan 300mg irbesartan online
buy temovate generic order amiodarone 100mg online cheap order amiodarone
purchase digoxin sale micardis 20mg usa molnupiravir 200mg tablet
buy dapoxetine without prescription buy avana 200mg pills buy motilium pill
doxycycline generic medrol 4mg without a doctor prescription cost of methylprednisolone
buy minocycline 100mg pills buy minocin 100mg pill terazosin ca
order cialis 40mg pill tadalafil non prescription buy ed meds online
order metformin 500mg for sale buy generic verapamil 240mg buy nolvadex 20mg
buy modafinil 200mg generic buy generic provigil 200mg oral phenergan
buy isotretinoin 40mg generic order deltasone 10mg generic order ampicillin 500mg without prescription
ivermectin 6 mg tablets order generic prednisone 40mg buy deltasone generic
order zofran 4mg sale cheap sulfamethoxazole trimethoprim brand
order accutane 10mg generic order zithromax online order zithromax 250mg pills
order prednisolone 40mg generic gabapentin 100mg us buy furosemide 40mg sale
buy monodox generic zovirax 800mg usa buy generic acyclovir 800mg
cheap coumadin order metoclopramide generic order allopurinol generic
zyrtec 5mg pills zyrtec online buy sertraline ca
buy cenforce 100mg pills order glucophage pill cheap glycomet 500mg
order prednisolone 40mg pills gabapentin online buy purchase furosemide pills
order atenolol 100mg generic methylprednisolone usa purchase femara generic
order xenical pills buy zovirax cheap buy zyloprim pill
crestor 20mg tablet purchase crestor generic generic motilium
order ranitidine 300mg pills meloxicam 7.5mg cheap celecoxib 200mg usa
plavix uk clopidogrel 150mg brand buy generic nizoral 200 mg
flomax 0.4mg usa zofran over the counter aldactone 100mg sale
order combivent 100mcg pill order decadron 0,5 mg pills order linezolid 600mg online cheap
nateglinide pill order candesartan 16mg without prescription brand atacand 16mg
duricef 250mg oral order lamivudine online brand propecia
order flagyl 400mg pill septra over the counter keflex 500mg without prescription
buy mebendazole 100mg pills retin over the counter order tadalafil 10mg
avana 100mg uk buy tadalafil 10mg without prescription diclofenac online order
buy tamoxifen 10mg generic buy generic ceftin over the counter order cefuroxime 250mg online
amoxicillin 250mg price amoxicillin 500mg uk clarithromycin 250mg cheap
buy bimatoprost pills order methocarbamol online buy desyrel 100mg sale
buy minocycline 100mg minocycline pills buy pioglitazone 15mg online
order tadalafil 10mg online cheap us viagra sales purchase tadalafil for sale
order azithromycin 250mg generic azithromycin 250mg over the counter buy neurontin 100mg sale
ivermectin 12 mg tablets buy ed pills generic deltasone 40mg over the counter
vardenafil sale hydroxychloroquine 400mg us plaquenil 400mg usa
olmesartan 10mg for sale buy olmesartan 20mg for sale divalproex 500mg over the counter
buy carvedilol tablets buy cenforce 50mg generic aralen 250mg
buy cheap diamox buy diamox generic azathioprine pill
lanoxin 250mg us telmisartan us molnupiravir 200 mg without prescription
naproxen 250mg cost naproxen 500mg tablet lansoprazole 15mg generic
order baricitinib generic buy metformin 1000mg online cheap buy atorvastatin 20mg online
generic montelukast 10mg order montelukast 5mg for sale avlosulfon us
buy nifedipine cheap buy perindopril buy fexofenadine 120mg