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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With