no coding needed

4 Replies - 1525 Views - Last Post: 04 May 2009 - 03:48 PMRate Topic:

Parallel Arrays

Posted 04 May 2009 - 12:31 AM

I need to create a file using user input data and parallel arrays. The data needs to be sorted, so the question I have is "Do I write the data to the file and then sort it or do I sort the data and then write it to the file?

Replies To: Parallel Arrays

Re: Parallel Arrays

Posted 04 May 2009 - 12:45 AM

You should sort the data first and then write it to the file.

And does the assignment specify that you must use parallel arrays? If not then you might want to consider doing it a little differently, parallel arrays usually aren't the easiest way to do things. If the assignment says you have to use them, then I guess you do, and it should be a good learning experience. :-)

Re: Parallel Arrays

Posted 04 May 2009 - 01:26 AM

Mikeyp926, on 3 May, 2009 - 11:45 PM, said:

You should sort the data first and then write it to the file.

And does the assignment specify that you must use parallel arrays? If not then you might want to consider doing it a little differently, parallel arrays usually aren't the easiest way to do things. If the assignment says you have to use them, then I guess you do, and it should be a good learning experience. :-)

-Michael

Yeah we have to use parallel arrays and we cannot uses classes just methods. Okay, so I need the same data to be written to two different files and sorted differently. So should I get the data, create two separate methods that sort and write the data to the file as it should be. I've found that it's quite complicated for beginning java class, I haven't found any java help sites that talk about sorting parallel arrays and writing it to a file.

Re: Parallel Arrays

Posted 04 May 2009 - 01:05 PM

Ok, well the writing the data to the files shouldn't be too difficult. I would think that the actual sorting would be the hard part, but I guess it depends on the assignment. I think the basic structure of the program would look like this.

1. Get user input and store in parallel arrays
2. Perform first sort on the arrays
3. Store the data in a file
4. Perform the second sort of the arrays
5. Store the data in a second file

Something like that.

What type of data are you sorting? Do you already have a good idea of how to perform the sorting?

Re: Parallel Arrays

Posted 04 May 2009 - 03:48 PM

Do not write a method that sorts and write to file

Write a method that sorts a parrallel array (the Code Snippet section contains sorts of all sorts [but not parrallel arrys I'm afraid])
Write a method that save an array to file... it could receive as parameter the array to write and the filename

for sorting parallel arrays just remember you will have to swap the elements in the 2 arrays at the same time