Does Foreach Item
in LinkedList
give items in strict order?
Is the strict order First=>Next=>Next=>...=>Last
respected in foreach or maybe is better to use while (item != null) ... item = item.Next
?
Yes. you can do that. For arrays, it will access elements in order. For other types (IEnumerable, or having GetEnumerator), it accesses elements in the order provided, through alternating MoveNext and Current calls.
Given two Linked Lists, create union and intersection lists that contain union and intersection of the elements present in the given lists. The order of elements in output lists doesn't matter.
Traversing through a linked list is very easy. It requires creating a temp node pointing to the head of the list. If the temp node is not null, display its content and move to the next node using temp next. Repeat the process till the temp node becomes null.
Yes, it does. See http://msdn.microsoft.com/en-us/library/aa664754(VS.71).aspx and how LinkedList enumerator respects the order.
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