/*1Planarity-Related Graph Algorithms Project2Copyright (c) 1997-2010, John M. Boyer3All rights reserved. Includes a reference implementation of the following:45* John M. Boyer. "Simplified O(n) Algorithms for Planar Graph Embedding,6Kuratowski Subgraph Isolation, and Related Problems". Ph.D. Dissertation,7University of Victoria, 2001.89* John M. Boyer and Wendy J. Myrvold. "On the Cutting Edge: Simplified O(n)10Planarity by Edge Addition". Journal of Graph Algorithms and Applications,11Vol. 8, No. 3, pp. 241-273, 2004.1213* John M. Boyer. "A New Method for Efficiently Generating Planar Graph14Visibility Representations". In P. Eades and P. Healy, editors,15Proceedings of the 13th International Conference on Graph Drawing 2005,16Lecture Notes Comput. Sci., Volume 3843, pp. 508-511, Springer-Verlag, 2006.1718Redistribution and use in source and binary forms, with or without modification,19are permitted provided that the following conditions are met:2021* Redistributions of source code must retain the above copyright notice, this22list of conditions and the following disclaimer.2324* Redistributions in binary form must reproduce the above copyright notice, this25list of conditions and the following disclaimer in the documentation and/or26other materials provided with the distribution.2728* Neither the name of the Planarity-Related Graph Algorithms Project nor the names29of its contributors may be used to endorse or promote products derived from this30software without specific prior written permission.3132THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"33AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE34IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE35DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR36ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES37(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;38LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON39ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT40(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS41SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.42*/4344#ifndef STACK_H45#define STACK_H4647#ifdef __cplusplus48extern "C" {49#endif5051// includes mem functions like memcpy52#include <string.h>5354typedef struct55{56int *S;57int size, capacity;58} stack;5960typedef stack * stackP;6162stackP sp_New(int);63void sp_Free(stackP *);6465int sp_Copy(stackP, stackP);6667int sp_CopyContent(stackP stackDst, stackP stackSrc);68stackP sp_Duplicate(stackP theStack);6970#define sp_GetCapacity(theStack) (theStack->capacity)7172#ifndef SPEED_MACROS7374int sp_ClearStack(stackP);75int sp_GetCurrentSize(stackP theStack);76int sp_SetCurrentSize(stackP theStack, int top);7778int sp_IsEmpty(stackP);79int sp_NonEmpty(stackP);8081#define sp_Push(theStack, a) { if (sp__Push(theStack, (a)) != OK) return NOTOK; }82#define sp_Push2(theStack, a, b) { if (sp__Push2(theStack, (a), (b)) != OK) return NOTOK; }8384int sp__Push(stackP, int);85int sp__Push2(stackP, int, int);8687#define sp_Pop(theStack, a) { if (sp__Pop(theStack, &(a)) != OK) return NOTOK; }88#define sp_Pop2(theStack, a, b) { if (sp__Pop2(theStack, &(a), &(b)) != OK) return NOTOK; }8990int sp__Pop(stackP, int *);91int sp__Pop2(stackP, int *, int *);9293int sp_Top(stackP);94int sp_Get(stackP, int);95int sp_Set(stackP, int, int);9697#else9899#define sp_ClearStack(theStack) theStack->size=0100#define sp_GetCurrentSize(theStack) (theStack->size)101#define sp_SetCurrentSize(theStack, Size) ((Size) > theStack->capacity ? NOTOK : (theStack->size = (Size), OK))102103#define sp_IsEmpty(theStack) !theStack->size104#define sp_NonEmpty(theStack) theStack->size105106#define sp_Push(theStack, a) theStack->S[theStack->size++] = a107#define sp_Push2(theStack, a, b) {sp_Push(theStack, a); sp_Push(theStack, b);}108109#define sp_Pop(theStack, a) a=theStack->S[--theStack->size]110#define sp_Pop2(theStack, a, b) {sp_Pop(theStack, b);sp_Pop(theStack, a);}111112#define sp_Top(theStack) (theStack->size ? theStack->S[theStack->size-1] : NIL)113#define sp_Get(theStack, pos) (theStack->S[pos])114#define sp_Set(theStack, pos, val) (theStack->S[pos] = val)115116#endif117118#ifdef __cplusplus119}120#endif121122#endif123124125