0

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..............

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by BestJewSinceJC
0

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.

0

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.

Edited by BestJewSinceJC: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.