wood burning stoves 2.0*
The moose likes Java in General and the fly likes LinkedList insert, remove and change Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "LinkedList insert, remove and change" Watch "LinkedList insert, remove and change" New topic
Author

LinkedList insert, remove and change

Alexie Chong
Greenhorn

Joined: Sep 16, 2011
Posts: 3
Dear Experts,

I am new to the LinkedList concept and trying out coding a LinkedList problem which require me to do Insert newInteger based on the Index, Remove Index and Change oldInteger to newInteger based on Index.
Please kindly advice what i should code in my

------------------------------------------------------------------------------------
Sample input

4 8
1 5 2 3
4
I 1 2
R 2
C 1 10
I 4 2

Sample output

YES
NO
NO
NO
------------------------------------------------------------------------------------

Here is my full code:

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14351
    
  22

Before writing any code, you need to understand what a linked list is and how it works, and what your three methods are supposed to do exactly. Once you understand exactly what needs to be done, you can start thinking about writing code.

So, do you understand how a linked list works? If not, then what about it don't you understand exactly?

Can you describe in English what you think should be done in the insert, remove and change methods?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39869
    
  28
And you need to check about equality. Don't use == for reference types (unless they are enum members), but at least the compiler will notice you are using = by mistake.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: LinkedList insert, remove and change