SORU
3 Mayıs 2009, Pazar


Nasıl ve Objective-C Sıra olun kullanırım?

Objective-C programımda kuyruk veri yapısı kullanmak istiyorum. C STL sıra kullanırdım. Objective-C eşdeğer veri yapısı nedir? Nasıl/pop öğeleri basacağım?

CEVAP
1 HAZİRAN 2009, PAZARTESİ


Ben bu sürümü bir sıra yerine yığın, biraz hızlandırdım yani

NSMutableArray QueueAdditions.h

@interface NSMutableArray (QueueAdditions)
- (id) dequeue;
- (void) enqueue:(id)obj;
@end

NSMutableArray QueueAdditions.m

@implementation NSMutableArray (QueueAdditions)
// Queues are first-in-first-out, so we remove objects from the head
- (id) dequeue {
    // if ([self count] == 0) return nil; // to avoid raising exception (Quinn)
    id headObject = [self objectAtIndex:0];
    if (headObject != nil) {
        [[headObject retain] autorelease]; // so it isn't dealloc'ed on remove
        [self removeObjectAtIndex:0];
    }
    return headObject;
}

// Add to the tail of the queue (no one likes it when people cut in line!)
- (void) enqueue:(id)anObject {
    [self addObject:anObject];
    //this method automatically adds to the end of the array
}
@end

Sadece ithalat .h yeni yöntemler kullanmak istediğiniz her yerde dosya, ve onları başka bir NSMutableArray yöntemleri gibi ara.

İyi şanslar ve Kodlama üzerinde Tutun!

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Andrea Lewis

    Andrea Lewis

    14 Mart 2013
  • Lupe Fiasco

    Lupe Fiasco

    23 ŞUBAT 2006
  • TheDroidDemos

    TheDroidDemo

    15 ŞUBAT 2011