Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. public class Node {
  2.  
  3. // When ever a new node is created the address will be null by default
  4.  
  5. public int data; // Data Field
  6. public Node next; // Address Field
  7.  
  8. // Constructor is to create the new node
  9. public Node(int data) {
  10. this.data = data; // set the data
  11. next = null; // set the address to null by default
  12. }
  13.  
  14.  
  15. }
  16.  
  17. public class InsertionInEndOfList {
  18.  
  19. private CustLinkedList mList;
  20.  
  21. public InsertionInEndOfList(CustLinkedList mList) {
  22. this.mList = mList;
  23. }
  24.  
  25. public CustLinkedList push() {
  26. System.out.println("===============================================");
  27. System.out.println("Enter the element to insert");
  28. Scanner input = new Scanner(System.in);
  29. if(new UtilCheckInteger(input).checkIsInteger()) {
  30. int selection = input.nextInt();
  31. //Create the node
  32. Node mNode = new Node(selection);
  33.  
  34. Node prevNode = mList.head;
  35. while(prevNode!=null) {
  36. prevNode = prevNode.next;
  37. }
  38.  
  39. prevNode.next=mNode;
  40.  
  41. } else {
  42. mList = new CreationOfList().initFunctionality();
  43. }
  44.  
  45. return mList;
  46. }
  47.  
  48. }
  49.  
  50. prevNode.next=mNode;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement