Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A Simple Objective-C Doubly Linked List
Objective-C C
branch: master

This branch is 28 commits behind mschettler:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
NSLinkedList.h
NSLinkedList.m
README

README

A Simple Doubly linked list for Objective-C
Linked Lists support efficient insertion/removal from anywhere in the list, whereas arrays are only efficient adding/removing to the end.

http://en.wikipedia.org/wiki/Linked_list
"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. Thus, many basic operations — such as obtaining the last node of the list, or finding a node that contains a given datum, or locating the place where a new node should be inserted — may require scanning most of the list elements."

Example Usage:

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

	[myList addObject:obj2];
	[myList addObject:obj3];
	[myList pushFront:obj1];

	// now contains obj1->obj2->obj3 in that order [NSStrings, or any object]
	
	// loop through, forward
	for (LNode *n = myList->first; n != nil; n=n->next) {
		NSString *theString = n->obj;
	
		NSLog(@"string: %@", theString);

	}

	// ...
	// ...

	[myList release];
					
Something went wrong with that request. Please try again.