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

📄 stack.cpp

📁 包括栈的pushpop,计数
💻 CPP
字号:
#include <iostream.h>
#include <stdlib.h>
#include "stack.h"
//typedef int ElementType;

void InitStack (Stack *S, int MaxSize)
{
	S->base = new ElementType[MaxSize];
	S->top = 0;
	S->StackSize = MaxSize;
}

void DestroyStack (Stack *S)
{
	delete S;
}

void ClearStack(Stack *S)
{
	S->top = 0;
	delete S->base;
}

bool Empty(Stack S)
{
	if (S.top==0)
		return true;
	else 
		return false;
}

int StackLength(Stack S)
{
	return S.top;
}

bool GetTop(Stack S,ElementType &e)
{
	if (S.top == 0)
		return false;
	else
	{
		e = *(S.base+S.top-1);
		return true;
	}
}

bool Push(Stack *S,ElementType e)
{
	if((S->top)==(S->StackSize))
		return false;
	else
	{
		*(S->base+(S->top)) = e;
		(S->top)++;
		return true;
	}

}

bool Pop(Stack *S,ElementType &e)
{
	if (S->top==0)
	{
		cout<<"empty"<<endl;
		return false;
	}
	else
	{
		e = *((S->base)+(S->top)-1);
		(S->top)--;
		return true;
	}
}

void Dec2Oct( int Dec)
{
/*	ElementType E;
	Stack *S;
	S = new Stack;	
	InitStack (S,10);
	cout<<"input the Decimal number:"<<Dec<<endl;;

	while (Dec)
	{
		Push(S,Dec%8);
		Dec = Dec/8;
	}
	cout<<"the octal number is:";
	while (Pop(S,E))
	{
		cout<<E;
	}*/
}

void Invert()
{
	char *a;
	a=new char[];
	cin.getline(a,100,'\n');

	ElementType E;
	Stack *S;
	S = new Stack;	
	InitStack (S,10);

	E = a;
	int i = 0;
	int j = 0;
	while (*(a+i)!='\0')
	{
		Push (S,E);		
		while (*(a+j)!=' ')
		{
			j++;
			i++;
		}
		*(E+j)='\0';
		E = a+j+1;
		j=0;
		i++;
	}
	Pop(S,E);
	cout<<E<<endl;
}

⌨️ 快捷键说明

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