public class MyList {

    private static class Node 
    {
        private final int data;
        private Node next;

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

        public void displayNode(){
            ;//System.out.print(Integer.toString(data.val)+ " ");
        }
        
    }

    private Node first;
    
    public MyList(){
        first = null;
        
    }
    
    
    public boolean isEmpty() {
        return (first == null);
    }

    

    
    public void insert(int data) {
        Node nod = new Node(data);
        
        
        if (isEmpty())
           {
               first= nod;
                return;
           }
        
        
        Node temp = first;
        
        
        while (temp.next != null)
        {
            temp = temp.next;
        }
        
       temp.next = nod;
        
        
    }
    
    
    
    public void print() {
       
        
        Node temp = first;
        
        
        while (temp != null)
        {   
            System.out.print(Integer.toString(temp.data)+ " ");
            temp = temp.next;
        }
        
       
        System.out.println(""); 
    }
    
    

    public Node filtraPos() 
    {
        
        if (isEmpty())
            return first;
            
        
        while (first.data <= 0 && first != null)
        {
            first = first.next;
        }
        
        if(first == null)
            return first;
        
        Node temp = first;
        Node next = temp.next;
        while (next != null)
        {
            if(next.data <= 0)
            {
                next = next.next;
                temp.next = next;
            }
            else
            {
                temp = next;
                next = temp.next;
            }
        }
        
        
        return first;

    }

	public static void main(String[] args) throws java.lang.Exception {
		MyList list = new MyList();
		
		list.insert(5);
		list.insert(5);
		list.insert(5);
		list.insert(5);
			list.insert(-5);
		list.insert(-5);
		list.insert(0);
		list.insert(-5);
		
		
		
		
		list.print();
		
		
		
		list.filtraPos();
		list.print();
		
		
		//System.out.println("Breadth First Search : ");
		
	}

}









Language Version:  JDK 9.0.1
