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 LogicPro Your Own Question

LogicPro
LogicPro, Engineer
Category: Homework
Satisfied Customers: 12491
Experience:  Expert in Java C++ C C# VB Javascript Design SQL HTML
29751445
Type Your Homework Question Here...
LogicPro is online now
A new question is answered every 9 seconds

In the C/C++ language, you can sort an array of data structures,

This answer was rated:

In the C/C++ language, you can sort an array of data structures, each of which occupies a lot of memory (like a kilobyte or more), much faster by assigning a similar array of pointers to point to the items in the other array, and then by swapping the pointers in place of swapping the more massive structures every time a swap must be done, and then at the end, doing a single reassignment of the elements of the original array once the correct order is known. But in Java, there are no user pointer variables that can be assigned the addresses of previously declared variables. So how can I do the same thing in Java that I just identified doing in C/C++?
Hi,
Welcome to JustAnswer.
My name is XXXXX XXXXX I will help you.

Can you provide me complete requirements?
What is the deadline?
Customer: replied 3 years ago.

I just want to be able to do this in Java like I can in C


 


Let me say that I have defined a class/structure type that I call a tylertown.


A single tylertown occupies 2 kilobytes of memory, and is made up of parts (fields) that are no more than 16 bytes each. I have an array of 600 tylertowns, and have defined a function that determines, for any two unequal tylertowns, which one is greater, and I want to sort these 600 tylertowns in ascending order. In C/C++, I would declare an array of 600 pointers to tylertowns, and assign every pointer in that array to a different one of the 600 tylertowns, then sort the 600 tylertowns by an algorithm that requires a series of swaps between tylertowns, but I would instead swap the pointers to those tylertowns involved every time a swap was made, until finally the pointers were in the correct order, and then copy the 600 tylertowns to another declared tylertown array in the correct order. If I didn't use pointers, it would take much longer, because at every swap I would have to transfer 2 kilobytes of information between variables instead of a single address between variables. So how can I do this sort with similar speed using Java?



I don't have a deadline

In java, there are no pointers. These are not needed as in java, we have objects which can point to(refer) similar type of objects. Whenever we sort an array of objects in Java, it swaps objects using references (until we use deep copy). This is like using pointers in c/c++.

If we use primitive types like int, float etc, swapping will take time. Java provides wrapper classes. We can wrap primitive type in its wrapper class and perform swapping.

 

One thing is obvious, Java will never be as faster as C++.
Hope it clears

Customer: replied 3 years ago.

Are you saying that if I swap the entire structure every time, in my example by assigning a declared tylertown the value of another tylertown, that behind the scenes Java assigns references, speeding the process up? If not, how can I temporarily copy (opposite of "deep copy") during the sort and then "deep copy" at the end?

THIS ANSWER IS LOCKED!

You need to spend $3 to view this post. Add Funds to your account and buy credits.
LogicPro and 3 other Homework Specialists are ready to help you