enter 5 nodes

if there is a number "3" entered, a number "4" is automatically inputed at the right side of number "3".

if there is a number "2" entered, a number "1" is automatically inputed at the left side of number "2".

can you help me dudes

you see im still a beginner........

hope for a nice reply..............

Recommended Answers

All 2 Replies

1. Read about LinkedLists on wikipedia or elsewhere
2. Use Java's LinkedList class
3. To insert things in a linked list, consult the documentation's insert method
4. To figure out where you should insert a value, you can easily use a LinkedList of Integer Objects, then search for the Integer with the value of one thing (such as "1"), which will return the index where "1" is found... so you know 2 will need to be inserted one index to the right.

I'll give you a small sample program to help you figure out the rest of this project on your own. If you don't show any effort though, you won't receive any more help.

LinkedList<Integer> list = new LinkedList<Integer>();
		list.add(2);
		int index = list.indexOf(2);
		list.add(index, 1);

P.S. I intentionally didn't do any error checking, but you should look at this link to see what happens if you search for something using indexOf which turns out isn't actually in your list. And you should read about the add method that I used to see why it does what you need it to do.

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.