dakrous 0 Newbie Poster

I am writing a doubly linked list, but i am having problems inserting. Here is my code for the node, and main. The issue is in the main when i call insert, it gives me null. How can i get the node to point to head, and tail(insert it).

Help me.

//NODE

/*
public class Node
{
    // instance variables - replace the example below with your own
    private String artist, title;
    private Node prev, next;
    /**
     * Constructor for objects of class Node
     */
    public Node()
    {
    }
    public Node(String artist, String title, Node prev, Node next)
    {
        this.artist = artist;
        this.title  = title;
        this.prev   = prev;
        this.next   = next;
    }
    
    public String getArtist()
    {
        return artist;
    }
    
    public String getTitle()
    {
        return title;
    }
    
    public Node getPrev()
    {
        return prev;
    }
    
    public Node getNext()
    {
        return next;
    }
    
    public void setArtist (String artist)
    {
       this.artist = artist;
    }
    
    public void setTitle(String title)
    {
        this.title = title;
    }
    
    public void setPrev(Node link)
    {
        prev = link;
    }
    
    public void setNext(Node link)
    {
        next = link;
    }

}

//////////////////////Main//////////////////////////////////

/*
 
import java.io.*;

public class SongList
{
    private Node head,tail;
    
    public SongList()
    {
        head = new Node();
        tail = new Node();
        
        head.setNext(tail);
        head.setPrev(null);
        
        tail.setNext(null);
        tail.setPrev(head);
    }

    public static void insert(String item, Node current)
    {
        Node theNode;
        theNode = new Node();

        theNode.getArtist();
        theNode.getTitle();
        
        theNode.setArtist(item);
        theNode.setTitle(item);
        
        theNode.setNext(current.getNext());
        current.setNext(theNode);
        
        theNode.setPrev(current);
        theNode.getNext().setPrev(theNode);
    }
    
    public void delete(Node current)
    {
        current.setNext(current.getNext().getNext());
        current.getNext().setPrev(current);
    }
 
    public static void main(String[] args) {

String add = "add";
String remove = "remove";
try 
{
String s = null;
String prompt = ">> ";
BufferedReader inData = new BufferedReader(new InputStreamReader(System.in));
System.out.print(prompt);
while ((s = inData.readLine()) != null && !s.equals("quit"))
 {
     Node doe = new Node();

     System.out.println("You entered : " + s);
if(s.equals(add))
{
String y = null;
System.out.println("Enter song title");
y = inData.readLine();

doe.setTitle(y);
insert(y,doe.getPrev());
System.out.println("y is " + " " + doe.getTitle());

System.out.println(" ");

String x = null;
System.out.println("Enter album name");
x = inData.readLine();
doe.setArtist(x);
System.out.println("x is " + " " + doe.getArtist());

System.out.println(" ");

}
if(s.equals(remove))
{

System.out.println(" ");
String z = null;
System.out.println("Enter song title");
z = inData.readLine();
doe.setTitle(z);
System.out.println("you removed " + doe.getTitle()+ " " +
" from your playlist");
System.out.println(" ");
}
System.out.print(prompt);
}

}
catch (Exception e){
System.out.println(e);
}
System.exit(0);
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.