Single Link List in java






import java.util.*;

class Intnode
{
  public int data;
  public Intnode next;
 
  Intnode()
  {
  this.next=null;
  }
}



public class Linklist
{
  public static void main(String[] args)
  {
   Scanner s = new Scanner(System.in);
   Intnode start= new Intnode();
   Intnode temp=start;
 
    System.out.println("Please enter data in the node");
    int k=s.nextInt();
start.data=k;

while(true)
{
 System.out.println("do u want to make more such node ? press y/n");
  char a= s.next().charAt(0);
 
  if(a=='n')
   break;

  Intnode temp2= new Intnode();
  System.out.println("Please enter data in the node");
       k=s.nextInt();
  temp2.data=k;
 
temp.next=temp2;
temp=temp.next;
}

temp =start;
while(temp!=null)
{
 System.out.print(temp.data+" ->");
 temp=temp.next;
}

  }

}

Comments

Popular posts from this blog

Getting Started With MEAN App Development with AngularJs , ExpressJs , NodeJs and MongoDB.

B. Dreamoon and WiFi :calculate no. of ways : recursive solution (branch and bound )

A. Dreamoon and Stairs : minimum steps to reach : recursion solution.