⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rstack.cpp

📁 工程LRTrans1
💻 CPP
字号:
// rstack.cpp: implementation of the rstack class.
//
//////////////////////////////////////////////////////////////////////

#include "rstack.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

rstack::rstack(int size)
	:m_size(size)
{
	assert(size > 0);
	m_sp = 0;
	m_sstack = new int[size];
	m_estack = new int[size];
	m_sematic = new int[size];
}

rstack::~rstack()
{
	delete[] m_sstack;
	delete[] m_estack;
	delete[] m_sematic;
}
void rstack::push(int s, int e, int v)
{
	if (m_sp < m_size)
	{
		m_sstack[m_sp] = s;
		m_estack[m_sp] = e;
		m_sematic[m_sp] = v;
		m_sp++;
	}
	else
	{
		printf("stack overflow! sp=%3d", m_sp);
		exit(1);
	}
}
int rstack::pop(int &s, int &e, int &v)
{
	if (m_sp > 0)
	{
		m_sp--;
		s = m_sstack[m_sp];
		e = m_estack[m_sp];
		v = m_sematic[m_sp];
		return s;
	}
	else
		return -1;
}

int rstack::top(int &s, int &e, int &v, int dist)
{
	//取离栈顶距离为dist的s,e,v
	assert(m_sp-dist-1 >= 0);
	s = m_sstack[m_sp-dist-1];
	e = m_estack[m_sp-dist-1];
	v = m_sematic[m_sp-dist-1];
	return m_sstack[m_sp-dist-1];
}

⌨️ 快捷键说明

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