Sunday, September 30, 2018

Length of linkedList

    public int findLengthLinkedList(Node nd){
    
    int size=0;
    if(nd==null)
    return 0;
    
    while(nd!=null){
    nd = nd.next;
    size++;
    }
    
    return size;
    }
    
    public int findLengthLinkedListRecursion(Node nd){
    
    if(nd==null)
    return 0;
    
    int size = findLengthLinkedListRecursion(nd.next)+1;
    return size;

    }

No comments:

Post a Comment