1/* 2********************************************************************** 3* Copyright (C) 2003-2011, International Business Machines 4* Corporation and others. All Rights Reserved. 5********************************************************************** 6*/ 7 8#include "uvector.h" 9 10U_NAMESPACE_BEGIN 11 12UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UStack) 13 14UStack::UStack(UErrorCode &status) : 15 UVector(status) 16{ 17} 18 19UStack::UStack(int32_t initialCapacity, UErrorCode &status) : 20 UVector(initialCapacity, status) 21{ 22} 23 24UStack::UStack(UObjectDeleter *d, UElementsAreEqual *c, UErrorCode &status) : 25 UVector(d, c, status) 26{ 27} 28 29UStack::UStack(UObjectDeleter *d, UElementsAreEqual *c, int32_t initialCapacity, UErrorCode &status) : 30 UVector(d, c, initialCapacity, status) 31{ 32} 33 34UStack::~UStack() {} 35 36void* UStack::pop(void) { 37 int32_t n = size() - 1; 38 void* result = 0; 39 if (n >= 0) { 40 result = elementAt(n); 41 removeElementAt(n); 42 } 43 return result; 44} 45 46int32_t UStack::popi(void) { 47 int32_t n = size() - 1; 48 int32_t result = 0; 49 if (n >= 0) { 50 result = elementAti(n); 51 removeElementAt(n); 52 } 53 return result; 54} 55 56int32_t UStack::search(void* obj) const { 57 int32_t i = indexOf(obj); 58 return (i >= 0) ? size() - i : i; 59} 60 61U_NAMESPACE_END 62