c_cpp 将队列和堆栈实现添加到NSMutableArray类

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 将队列和堆栈实现添加到NSMutableArray类相关的知识,希望对你有一定的参考价值。

#import "NSMutableArray+QueueAndStack.h"

@implementation NSMutableArray (QueueAndStack)
// Queues are first-in-first-out, so we remove objects from the head
-(id)queuePop {
    if ([self count] == 0) {
        return nil;
    }
    
    id queueObject = [self objectAtIndex:0];
    
    [self removeObjectAtIndex:0];
    
    return queueObject;
}

// Add to the tail of the queue
-(void)queuePush:(id)anObject {
    [self addObject:anObject];
}

//Stacks are last-in-first-out.
-(id)stackPop {
    id lastObject = [self lastObject];
    
    if (lastObject)
        [self removeLastObject];
    
    return lastObject;
}

-(void)stackPush:(id)obj {
    [self addObject: obj];
}
@end
#import <Foundation/Foundation.h>

@interface NSMutableArray (QueueAndStack)
-(id)queuePop;
-(void)queuePush:(id)obj;
-(id)stackPop;
-(void)stackPush:(id)obj;
@end

以上是关于c_cpp 将队列和堆栈实现添加到NSMutableArray类的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp C ++标准库中的堆栈和队列的简单示例

python列表实现堆栈和队列

c_cpp 使用类和数组实现堆栈

如何用Python实现堆栈和队列详细讲解

c_cpp 使用类和链接列表实现堆栈

c_cpp 使用类和向量进行堆栈实现