How to iterate through Linked List

前端 未结 4 1467
挽巷
挽巷 2021-01-12 08:12

I have looked around and I can\'t really find an answer I can understand or it doesn\'t apply to me. I have this class:

class Node
{
    public int value;
           


        
4条回答
  •  不知归路
    2021-01-12 09:12

    You iterate through your class as follows:

    var currentNode = head;
    while ((currentNode != null) && (currentNode.Value != desiredValue))
       currentNode = currentNode.next;
    

    When the while loop completes, currentNode will be null or contain a node with the desired value.

提交回复
热议问题