How to implement linked list in objective-c?

Possible duplicate:
Creating linked lists in a C object

I am trying to understand what a linked list is. Is there a way to implement it in Objective-C or in some sample code?

+4
source share
2 answers

A linked list is useful in C for processing dynamic-length lists. This is not a problem in objective-C, since you have NSMutableArray .

So the equivalent is:

 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; 

Will be:

 NSMutableArray* array = [[NSMutableArray alloc] init]; [array addObject:[NSNumber numberWithInt:5]]; [array addObject:[NSNumber numberWithInt:10]]; 

Of course, you can use the classic linked list in an objective-C application.

+7
source

no need to use an array. The MyEvent object is also conitan next MyEvent . so you just create the next next object. so you only need to initialize.

eg.

 MyEvent *obj = [[MyEvent alloc]init]; 

child node.

 obj.nextEvent = [[MyEvent alloc]init]; 
+2
source

Source: https://habr.com/ru/post/1434582/


All Articles