Advertisement
Guest User

Untitled

a guest
Feb 14th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. public class Node
  2. {
  3. public int data;
  4. public Node link;
  5.  
  6. public static Node oddEvenList (int[] ar)
  7. {
  8. Node first;
  9.  
  10. }
  11.  
  12. public static Node insertNode(Node root, int nextNode)
  13. {
  14. Node temp = new Node();
  15. Node node;
  16. temp.data = nextNode;
  17. temp.link = null;
  18.  
  19. if (root == null)
  20. {
  21. root = temp;
  22. }
  23. else
  24. {
  25. node = root;
  26. while (node.next != null)
  27. node = node.next;
  28. node.next = temp;
  29. }
  30. return root;
  31. }
  32.  
  33. public static Node toList (int[] ar)
  34. {
  35. Node root = null;
  36. for (int i = 0; i < ar.length; i++)
  37. root = insertNode(root, arr[i]);
  38. return root;
  39. }
  40.  
  41. }
  42.  
  43. public static void main(String[] args)
  44. {
  45. int[] ar = {4,16,8,5,24,17,25};
  46. Node root = toList(ar);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement