Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Monday, January 1, 2018

Strcmp LinkedList


int compare(Node node1, Node node2)
    {
      while(node1!=null && node2!=null)
      {
          if(node1.data!=node2.data)
          {
              if(node1.data>node2.data)
              return 1;
              return -1;
          }
          node1=node1.next;
          node2=node2.next;
      }
      if(node1!=null)
      return 1;
      if(node2!=null)
      return -1;
      return 0;
    }

0 Comments:

Post a Comment

Stats