I wrote a program to implement LinkedList :

package JavaApplication;
import JavaApplication.MyExciption;
public class LinkedList<ListElementType>
{
class Node
{
ListElementType elem;
Node next;
}
private Node head;
private Node tail;
private Node current;
public LinkedList()
{
head=null;
tail=null;
current=null;
}
public void insert(ListElementType elem)throws MyExciption
{
Node addedNode=new Node();
if(addedNode==null)
throw new MyExciption("An ERROR happened : There is no enough memory to add new element.");
addedNode.elem=elem;
if(head==null)
head=addedNode;
else
tail.next=addedNode;
tail=addedNode;
addedNode.next=null;
}
public boolean first(ListElementType elem)
{
if(head==null)
return false;
elem=head.elem;
current=head;
return true;
}
public boolean next(ListElementType elem)throws MyExciption
{
if(current==null)
throw new MyExciption("An ERROR happened : The list is Empty.");
if(current.next==null)
return false;
current=current.next;
elem=current.elem;
return true;
}
}


and then I wrote a main program to store char items and then displaying them again on console:


package Example;
import java.util.Scanner;
import org.omg.CORBA.CharHolder;
import JavaApplication.LinkedList;
import JavaApplication.MyExciption;
import static java.lang.System.*;
public class LinkedListTest
{
public static void main(String[]args) throws MyExciption
{
LinkedList<CharHolder> L=new LinkedList<CharHolder>();
CharHolder elem =new CharHolder();
out.println("Enter items to add to add to List, add q to stop");
Scanner read=new Scanner(in);
boolean iterator=true;
do
{
String s=read.next();
char[]a=s.toCharArray();
for(int j=0;j<a.length;j++)
{
if(a[j]!='q')
{
CharHolder e=new CharHolder();
e.value=a[j];
L.insert(e);
}
else
{
iterator=false;
break;
}
}
}while(iterator);
out.println("Here are the items in the list : ");
boolean notEmpty=L.first(elem);
while(notEmpty)
{
out.print(elem.value+" ");
notEmpty=L.next(elem);
}
}
}

After running the results is:

Enter items to add to add to List, add q to stop
ytrewq
Here are the items in the list :

As you can see, the result is blanks...

please, need help.

bad package names.
unformatted code.
and what do you think is wrong?

what happened to you!!
People..

which means by "bad package names"
the code is running, but it doesn't insert in the list although the code is correct .It inserts the default value of class CharHolder which is blank..

Please, I need help from who knows java very GOOD
not to tell me "bad package names" ??????

jwenting is one of the most knowledgeable members concerning Java we have, he can be a little abrasive though. ;) Bad package names because they do not follow naming conventions. He is also right about the format and it needs to be in [CODE=java] [/code] Code needs to be in CAPS.

[CODE=java] [/code] Code needs to be in CAPS.

doesn't matter if they capital or lower case as long they typed correctly and without any spaces, you can try it on your next post ;)

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.