순서 스 택 관련 작업 (C 언어)

1303 단어 데이터 구조
//Stack.h
#pragma once

#define MAX_SIZE 100
typedef char StackDataType;
typedef struct Stack {
	StackDataType array[MAX_SIZE];
	int top;   //      
}Stack;

//    /  
//  (     )/ (      )/ (        )
//    /     /    
//   ->       
//   ->       

void StackInit(Stack* pStack);
void StackDestroy(Stack* pStack);
void StackPush(Stack* pStack, StackDataType data);
void StackPop(Stack* pStack);
StackDataType getTop(Stack* pStack);
int getSize(Stack* pStack);
int StackIsEmpty(Stack* pStack);
int StackIsFull(Stack* pStack);
//Stack.c
#include "Stack.h"
#include 
void StackInit(Stack* pStack)
{
	pStack->top = 0;
}
void StackDestroy(Stack* pStack)
{
	pStack->top = 0;
}
void StackPush(Stack* pStack, StackDataType data)
{
	assert(pStack->top < MAX_SIZE);
	pStack->array[pStack->top++] = data;
}
void StackPop(Stack* pStack)
{
	assert(pStack->top > 0);
	pStack->top--;
}
StackDataType getTop(Stack* pStack)
{
	assert(pStack->top > 0);
	return pStack->array[pStack->top-1];
}
int getSize(Stack* pStack)
{
	return pStack->top;
}
int StackIsEmpty(Stack* pStack)
{
	return pStack->top <= 0;
}
int StackIsFull(Stack* pStack)
{
	return pStack->top >= MAX_SIZE;
}

좋은 웹페이지 즐겨찾기