Posts

Showing posts with the label add three node at specific position

add three node at specific position

add three node at specific position Scanner in=new Scanner(System.in); //insert 3 node at a position public void add3Node() { System.out.println("enter postion:"); int position=in.nextInt(); if(position>0&&position<=size+1) { System.out.println("enter value of first node:"); int n1d=in.nextInt(); System.out.println("enter value of first node:"); int n2d=in.nextInt(); System.out.println("enter value of first node:"); int n3d=in.nextInt(); Node n3=new Node(n3d,null); Node n2=new Node(n2d,n3); Node n1=new Node(n1d,n2); if(position==1) { size++; size++; size++; if(size==0) { start=n1; } else { n3.setNext(start); start=n1; } } else if (position==size+1) { size++; size++; size++; Node t; t=start; while(t.getNext()!=null) { t=t.getNext(); } t.setNext(n1); } else { size...