stack.cpp

来自「主要实现了波兰式和逆波兰式的转换」· C++ 代码 · 共 77 行

CPP
77
字号
// STACK.cpp: implementation of the STACK class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TRANS.h"
#include "STACK.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

STACK::STACK()
{

}

STACK::~STACK()
{

}

void STACK::DestroyStack(LinkStack &s)//销毁栈
{
	LinkStack p,temp=s;
	while(temp)
	{
		p=temp;
		temp=temp->next;
		free(p);
	}
}


void STACK::InitStack(LinkStack &s)  //初始化  
{
	LinkStack p=new LNode;
	p->St=NULL;
	p->next=NULL;
	s=p;
}

void STACK::Push(LinkStack &s, char* str)//入栈
{
	LinkStack temp=new LNode;
	
	SNode*p=new SNode;
	temp->St=p;
	temp->next=s;
	s=temp;
	

   strcpy(s->St->c,str);
}



void STACK::Pop(LinkStack &s, char *str)//出栈
{
	LinkStack temp=s;
	strcpy(str,temp->St->c);
	 
	s=s->next;
}

void STACK::GetTop(LinkStack &s,char *str)
{
	strcpy(str, s->St->c);

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?