Wednesday, 23 August 2017

Learning To Code Part 1(Technically Not)

 

I am going to straightly jump into what I learned recently, today to be precise. And that thing is.....Linked List. Something that I never understood from college professors but now as things a little less stressful I am getting a hang of it. 

The concept of linked list was pretty much cleared when I happened to have asked a really stupid question on StackOverflow. 

The question was basically, I was supposed to add a linkedlist let's call it linkedlistB to linkedlistA.
Now, that I know what simply I need to do, I will just tell you what one needs to do.

public static Node (Node headA, Node headB)
{
    currentA = headA;
    currentB = headB;

    while ( currentA.nextLink != null)
    {
        currentA = currentA.nextLink;
    }

    Node joiningNode = currentB;
    currentA.nextLink = joiningNode;             //Attaching the nextLink of last node of  LinkedListA to
                                                                          first node of LinkedListB
    
    currentA = headA;
   
    while ( currentA.nextLink != null)           //This while loop is going to print data of nodes
     {
         System.out.println(currentA.data);     
         currentA = currentA.nextLink;
     }
     currentA = headA;

     return headA;




No comments:

Post a Comment