📄 cd3_1u.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "cd3_1u.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
Tform1 *form1;
#define max 5 //定义max为5
String stack[max]; //定义stack数组为字符串数组,其长度为5
static int top=-1; //定义top为静态整数型变量,其值为-1
int i;
//---------------------------------------------------------------------------
__fastcall Tform1::Tform1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall Tform1::endClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall Tform1::inpKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key==13) //Enter键所传来的key值为13
{
if(top>=max-1) //当堆栈满时显示空间已满,并停止输入
{
lf->Color=255; //颜色可用数字表示Color=R+G*256+B*256*256
lf->Caption=" Full";
}
else
{
top++; //顶端索引值加1
stack[top]=inp->Text; //将输入的字符串存于stack数组中
inp->Text=" ";
if(top!=-1) //清除堆栈已空的提示画面
{
le->Color=210+210*256+210*256*256;
le->Caption=" ";
}
for(i=top;i>=0;i--)
ssg->Cells[0][(max-1)-i]=stack[i]; //将堆栈值用字符串表格输出
}
}
switch(top) //即时显示top位置的决策设置
{
case 0:t_1->Caption=" ";
t0->Caption="Top=0";
break;
case 1:t0->Caption=" ";
t1->Caption="Top=1";
break;
case 2:t1->Caption=" ";
t2->Caption="Top=2";
break;
case 3:t2->Caption=" ";
t3->Caption="Top=3";
break;
case 4:t3->Caption=" ";
t4->Caption="Top=4";
break;
}
}
//---------------------------------------------------------------------------
void __fastcall Tform1::popClick(TObject *Sender)
{
if(top>-1) //当top<=-1时没有数据可输
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -