Possible Duplicate:
Creating Linked Lists in Objective C
I am trying to understand what a linked list is. Is there anyway of implementing it in Objective-C or some sample code?
Possible Duplicate:
Creating Linked Lists in Objective C
I am trying to understand what a linked list is. Is there anyway of implementing it in Objective-C or some sample code?
Linked list are useful in C to handle dynamic-length lists. This is not an issue in objective-C as you have NSMutableArray
.
So the equivalent of:
struct my_list {
int value;
struct my_list *next;
};
struct my_list list1;
struct my_list list2;
list1.next = &list2;
list1.value = 5;
list2.value = 10;
Would be:
NSMutableArray* array = [[NSMutableArray alloc] init];
[array addObject:[NSNumber numberWithInt:5]];
[array addObject:[NSNumber numberWithInt:10]];
Of course, you can use classic linked-list in an objective-c application.
there is no need to use of array. MyEvent object also conitan next MyEvent. so you just create next of next object. so just you need to init.
e.g.
MyEvent *obj = [[MyEvent alloc]init];
child node.
obj.nextEvent = [[MyEvent alloc]init];