Click here to Skip to main content
15,907,326 members
Home / Discussions / Java
   

Java

 
AnswerRe: help me Pin
Richard MacCutchan24-Feb-11 23:10
mveRichard MacCutchan24-Feb-11 23:10 
AnswerRe: help me Pin
RaviRanjanKr25-Feb-11 19:37
professionalRaviRanjanKr25-Feb-11 19:37 
QuestionBlock desktop until app running? Pin
Alok Sharma ji22-Feb-11 1:37
Alok Sharma ji22-Feb-11 1:37 
AnswerRe: Block desktop until app running? Pin
Nagy Vilmos22-Feb-11 1:45
professionalNagy Vilmos22-Feb-11 1:45 
AnswerRe: Block desktop until app running? Pin
TorstenH.23-Feb-11 20:07
TorstenH.23-Feb-11 20:07 
AnswerRe: Block desktop until app running? Pin
jschell24-Feb-11 11:59
jschell24-Feb-11 11:59 
GeneralRe: Block desktop until app running? Pin
Alok Sharma ji24-Feb-11 20:32
Alok Sharma ji24-Feb-11 20:32 
QuestionRecursion:Delete from a linkedList Pin
Brian Robertson21-Feb-11 22:08
Brian Robertson21-Feb-11 22:08 
import java.io.*;
import java.util.*;

class LinkedList<T>
{
	private Node head;
	private Node last;
	private T data;

	public LinkedList()
	{
		head = null;
	}

	public boolean isEmpty()
	{
		return (head==null);
	}


	public void addToHead (T val)
	{
		Node n = new Node (val);
		n.next = head;
		head = n;
	}


	private class Node
	{
        public T data;
        public Node next;

        Node (T val)
        {
        	data = val;
        	next = null;
        }
	}




public void delete(T val)
{
	delete(head, val);
}

 public Node delete (Node curr, T val)
  {

  		Comparable <T> temp = (Comparable<T>)val;
		if (curr==null)
		{
			System.out.println("list empty");
		}else if ( temp.compareTo(curr.data)==0){
				curr = curr.next;
			}else{
				curr.next = delete(curr.next, val);
			}
			return curr;
 }



    public String toString()
    {
    	String str ="";
    	Node curr = head;
    	while(curr!=null)
    	{
    		str = str + curr.data + " ";
    		curr = curr.next;
    	}
    	return str + "\n";
    }




}//end linkedList

class Link
{
	public static void main(String[] arg)
	{
		LinkedList<Integer> s1 = new LinkedList<Integer>();
		s1.addToHead(23);
		s1.addToHead(78);
		s1.addToHead(100);

		s1.delete(23);
		System.out.println(s1.toString());
	}
}


I am writing the code above to delete a node from a linkedlist using recursion.
Questions
1. Is there another way I can rewrite the method without using Comparable?
2. The program compiles but give the following error all the time, How can i rectify this?

Note: C:\Users\antonio\Desktop\Link2.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

AnswerRe: Recursion:Delete from a linkedList Pin
Nagy Vilmos22-Feb-11 1:44
professionalNagy Vilmos22-Feb-11 1:44 
AnswerRe: Recursion:Delete from a linkedList Pin
David Skelly22-Feb-11 1:50
David Skelly22-Feb-11 1:50 
QuestionPalindrome assignment Pin
Chuon Visoth21-Feb-11 14:04
Chuon Visoth21-Feb-11 14:04 
AnswerRe: Palindrome assignment Pin
shivamkalra21-Feb-11 15:21
shivamkalra21-Feb-11 15:21 
GeneralRe: Palindrome assignment Pin
Chuon Visoth21-Feb-11 15:36
Chuon Visoth21-Feb-11 15:36 
GeneralRe: Palindrome assignment Pin
shivamkalra21-Feb-11 15:41
shivamkalra21-Feb-11 15:41 
GeneralRe: Palindrome assignment Pin
Chuon Visoth21-Feb-11 15:45
Chuon Visoth21-Feb-11 15:45 
GeneralRe: Palindrome assignment Pin
shivamkalra21-Feb-11 15:48
shivamkalra21-Feb-11 15:48 
GeneralRe: Palindrome assignment Pin
Chuon Visoth21-Feb-11 15:50
Chuon Visoth21-Feb-11 15:50 
GeneralRe: Palindrome assignment Pin
shivamkalra21-Feb-11 15:54
shivamkalra21-Feb-11 15:54 
AnswerRe: Palindrome assignment Pin
TorstenH.21-Feb-11 20:48
TorstenH.21-Feb-11 20:48 
GeneralRe: Palindrome assignment Pin
Chuon Visoth23-Feb-11 13:37
Chuon Visoth23-Feb-11 13:37 
GeneralRe: Palindrome assignment Pin
TorstenH.23-Feb-11 19:34
TorstenH.23-Feb-11 19:34 
QuestionDeveloping Lotus Notes Plugin : What does "navigate to the JRE in the Notes installation folder" means? Pin
eight20-Feb-11 16:23
eight20-Feb-11 16:23 
AnswerRe: Developing Lotus Notes Plugin : What does "navigate to the JRE in the Notes installation folder" means? Pin
Richard MacCutchan21-Feb-11 0:47
mveRichard MacCutchan21-Feb-11 0:47 
GeneralRe: Developing Lotus Notes Plugin : What does "navigate to the JRE in the Notes installation folder" means? Pin
eight21-Feb-11 16:22
eight21-Feb-11 16:22 
GeneralRe: Developing Lotus Notes Plugin : What does "navigate to the JRE in the Notes installation folder" means? Pin
Richard MacCutchan21-Feb-11 21:54
mveRichard MacCutchan21-Feb-11 21:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.