Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Node {
- // When ever a new node is created the address will be null by default
- public int data; // Data Field
- public Node next; // Address Field
- // Constructor is to create the new node
- public Node(int data) {
- this.data = data; // set the data
- next = null; // set the address to null by default
- }
- }
- public class InsertionInEndOfList {
- private CustLinkedList mList;
- public InsertionInEndOfList(CustLinkedList mList) {
- this.mList = mList;
- }
- public CustLinkedList push() {
- System.out.println("===============================================");
- System.out.println("Enter the element to insert");
- Scanner input = new Scanner(System.in);
- if(new UtilCheckInteger(input).checkIsInteger()) {
- int selection = input.nextInt();
- //Create the node
- Node mNode = new Node(selection);
- Node prevNode = mList.head;
- while(prevNode!=null) {
- prevNode = prevNode.next;
- }
- prevNode.next=mNode;
- } else {
- mList = new CreationOfList().initFunctionality();
- }
- return mList;
- }
- }
- prevNode.next=mNode;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement