Is linked is tougher or easier? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is linked is tougher or easier?

how to make it easy

18th Mar 2017, 11:31 AM
Nallish
Nallish - avatar
2 Answers
+ 1
For beginners I would not say LinkedList is easier, requires more on the handling than simply Lists and arrays. While you can use foreach loop for the last two mentioned, LinkedList handled more in a manual way. Instead of .Add() there are .AddFirst() and .AddLast() methods. The first adds the element to the beginning of the list/chain, the second puts it onto its end, like List.Add() does. Rolling thru its elements is toughter a bit: LinkedList<Type> list = new LinkedList<Type>(); ... add elements ... LinkedListNode<Type> node = list.First; while (node != null) { ... use node ... node = node.Next; } Or backwards: LinkedListNode node = list.Last; while (node != null) { ... use node ... node = node.Previous; }
7th Apr 2017, 1:00 PM
Magyar Dávid
Magyar Dávid - avatar
0
thank you
8th Apr 2017, 5:57 AM
Nallish
Nallish - avatar