JeaminW / CKLinkedList

A Simple Objective-C Doubly Linked List

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

###A Doubly linked list for Objective-C

"The principal benefit of a linked list over a conventional array is that the order of the linked items may be different from the order that the data items are stored in memory or on disk. For that reason, linked lists allow insertion and removal of nodes at any point in the list, with a constant number of operations. On the other hand, linked lists by themselves do not allow random access to the data, or any form of efficient indexing. "

###Installation

  1. Add CKLinkedList.h and CKLinkedList.m to your project
  2. Add #import "CKLinkedList.h" to your project's .pch file
  3. CKLinkedList class is now available anywhere in your project, enjoy!

###Benefits vs. NSArray

  • Efficient insertion and removal of elements at any index
  • Efficient memory allocation (No need to resize/reallocate memory)

###Example Usage

CKLinkedList *myList = [[CKLinkedList alloc] init];

[myList addObject:obj2];  // add object to end of list
[myList addObject:obj3];  // add object to end of list
[myList pushFront:obj1];  // add object to front of list, no performance penalty

// linked list now contains obj1->obj2->obj3 in that order [NSStrings, or any object]

// manual loop through list, forward
for (LNode *n = myList->first; n; n=n->next) {
	NSString *theString = n->obj;
	NSLog(@"string: %@", theString);
}

// ...
// ...

[myList release];

###Testing

  • Execute make test to run the test suite

About

A Simple Objective-C Doubly Linked List

License:The Unlicense


Languages

Language:Objective-C 98.3%Language:Makefile 1.7%