How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Raj Your Own Question
Raj, Engineer
Category: Homework
Satisfied Customers: 1290
Experience:  4 + Experiance in IT Industry
Type Your Homework Question Here...
Raj is online now
A new question is answered every 9 seconds

In a language such as C++ with pointers you can construct a

This answer was rated:

In a language such as C++ with pointers you can construct a linked list, or chain, where you have a class that can act as a node or a link, and that class includes a pointer to that same type of class, so that from a declared object of that class you can allocate dynamically another object of that class through that pointer, and from the new object you can allocate another new object from the poiner of that latter object, etc. But then, and this is important, with the list fully formed you can delete a link by taking the pointer of one object in the chain and repointing it to a different object, like a link further down the chain. By similarly repointing pointers, you can also insert new links into the chain between two existing links, or even create a circular linked list by pointing the pointer of a latter link to an object that preceeded it in the chain, or a doubly linked list by the class having two such pointers, one to point to its succesor and the other one to point to its predecesor. I need to be able to do this in Java, which doesn't have pointers. How can I do this in Java?
Hi there,

I will be helping you with the solution.
You need the concept of how to use it in java or do you need a code to demonstrate how it can be achieved in java?

Thank you
Customer: replied 3 years ago.

What I need is how I can do what I described in Java, particularly the insertion of new links (between links) or deletion (from between links) of links no longer wanted. The critical thing is that in C++ (or Ada or Pascal, or any other language with pointers), I can assign a pointer to point to a pre existing object

In Java we can achieve the requirement by creating a node class which will have two objects of type node(itself data type)
These node is now like a pointer with one value variable and the two objects of node type with name left andrights which will be acting as pointers.
Initialize left and right to null and put the mutator and accessor methods for all three bariables.

Now you can use the node as pointer in your main code and change the pointing property using the accessor and mutator methods.

Got the concept?

If my answer was helpfull than dont forget to RATE MY ANSWER.
Customer: replied 3 years ago.

the node class must be a new Java feature. I only have books that cover older versions of Java, so I don't know how to use the node class, or anything about it. Can you please show me how to use it? Can you please show me an example of its use to insert a new link between two preexiting consecutive links in a linked chain?

Actually node class is not an inbuilt feature in java it will be a customized class created by us to act as a linked list.

I will provide you the sample code to demonstrate it in next few hrs.
Customer: replied 3 years ago.

If you have to create a customized class yourself, then that class must contain objects that act as pointers (the objects of node type), and you must be able to assign these to point to preexisting nodes, but Java does not have pointers.

Will post you a sample code in next 2 - r hrs.
Yes Java does not have pointers but you can customize the classes in a way that it can be used with functionality as a pointer.

Do you want me to work on the code to demonstrate that??
Customer: replied 3 years ago.

yes, please provide me with some example of code that demonstrates that.

The reason I chose insertion of a link into a chain, between preexisting links, is that it forces you to declare a new link dynamically ("on the heap") and also to repoint pointers, that pointed to given links, to point to other links instead, preexisting links.

What software do you use to run JAVA Code. Is it Netbean, Eclipse or any other?
Customer: replied 3 years ago.

I use Java version 1.6.0 I compile the code and link and execute it using its commands. I use a microsoft windows XP based personal computer. I have never heard of "Netbean" or "Eclipse". But just show me the code that you think will work, in a text file

Ok No Problem I will provide you the JAVA Code file.

Give me 30 min and I will provide you the code.

You need to spend $3 to view this post. Add Funds to your account and buy credits.
Raj and other Homework Specialists are ready to help you
Customer: replied 3 years ago.

oh, I think I understand. Any object variable automatically acts as a pointer, and you can either dynamically allocate a new value for that object pointer or assign it to another object, a preexisting object, of the same type. It finally "clicked" in my head.

Yes, Thats what I was trying to explain you.
Since using the functions mutator and accessor we can change its value any time so we can create the functioning of pointers for linked list using this concept even when there is no Pointer support in JAVA.

Thank you for your Feedback

In Future to request any new Question to me just begin your Question with TO RAJ followed by the Question in the following format:

TO RAJ: Followed by the Question.

Have a Good Day.
Customer: replied 3 years ago.

I have a new question (new fee?) to ask you about Java, something else that I have done with C++ and would like to know how to do it with Java. This one involves the RandomAccessFile class, how to use it to input and output BigDecimal objects

Yes i can help you but you will have to post a new question for that and fee will depend on the effort so post a new question beginning with TO RAJ followed by the question.

Thank you