![]()
|
stack Specification SheetPortable Object Compiler (c) 1998. All Rights Reserved.
StackInherits from: Cltn
Class DescriptionStack instances are collections that maintain their entries in LIFO (last in first out) order. Although Stacks are most often controlled by the push: and pop methods, the class also provides for random access of the stack, through the at: and removeAt: methods. Note that the indices are relative to the top (last added) item on the stack, which is the opposite of how the OrdCltn class works.
Method typesCreationInterrogationAddingPrintingMethodsnew+newReturns a new empty stack.
new:+new:(unsigned)nReturns a new empty stack, that can hold n objects.
copy-copyReturns a new copy of the stack.
deepCopy-deepCopyReturns a new copy of the stack. The members in the new stack are deep copies of the members in the original stack.
emptyYourself-emptyYourselfRemoves all the members of the stack (without freeing them). Returns the receiver.
freeContents-freeContentsRemoves and frees all the members of the receiver, but doesn't free the receiver itself. Returns the receiver.
free-freeFrees the stack, but not its contents. Returns nil. Do :
if you want to free the collection and its contents.aCltn = [[aCltn freeContents] free];
depth- (unsigned)depthReturns the number of objects on the stack.
isEmpty- (BOOL)isEmptyWhether the number of objects on the stack is equal to zero.
eachElement-eachElementReturns a sequence of the elements in the collection.
aSeq = [myStack eachElement]; while ((anElement = [aSeq next])) { /* do something */ } aSeq = [aSeq free]; topElement-topElementReturns the top element on the stack, without removing it. Returns nil if there are no elements on the stack.
push:-push:anObjectPushes anObject on the stack, so that it becomes the top of the stack. Returns self.
pop-popPops the top of the stack and returns it. Returns nil if the stack is empty.
swap-swapExchanges the top two stack items and returns the receiver. Generates an exception if the stack is not at least two items deep.
at:-at:(unsigned )anOffsetReturns the object at anOffset. Note that the top of the stack is at offset 0.
removeAt:-removeAt:(unsigned )anOffsetRemoves the object at anOffset. Note that the top of the stack is at offset 0.
printOn:-printOn:(IOD)aFilePrints a list of the objects in the objects by sending each individual object a printOn: message. Returns the receiver.
|