Questions tagged [parallel-arrays]

Use for questions about using in separate array per field (I.e. `name[10], subject[10], grade[10]`.) to store structured records instead of array of objects with fields/properties.

This tag is for questions that concern usage of multiple (parallel) arrays to store records in array-per-field manner (vs. using classes to store fields of an entity together and than have a single array of such entities). See Wikipedia for more information.

Example of parallel arrays (JavaScript-like language):

   var names = ["Bob", "Alice"];
   var subject = ["Crypto", "Compression"];
   var grades = [9002, 9001];

Same data as objects:

   var students = [
     {name:"Bob", subject: "Crypto", grade: 9002},
     {name:"Alice", subject: "Compression", grade: 9001}
   ];

Cases when you would use parallel arrays:

  • arrays is the only data structure you know or "should" know depending on how far you in the programming course. If that is the case make sure to clearly spell out in the question, especially if assignment in question calls for using arrays.
  • your specific case shows significant benefits of using parallel array to store the data. Add reasoning and, ideally, performance measurements to the question. Expect alternative suggestions to represent the data as valid answers.
71 questions
1
vote
2 answers

how to print Scanner element using parallel arrays in java?

I am new to learning about parallel arrays and want to know how to effectively print content/elements using parallel array only, I tried but couldn't get it to work and function the way I want. The task is: The program inputs an integer from the…
user13486009
1
vote
2 answers

Java: Resizable Arraylists are won't stay parallel

I have a situation where my 'agent' objects contain a vast amount of data, including graphics, physics, and now also ai. I was previously coding components of these 'agents' in separate objects, that were parallel. Now I realize, since the agents…
bigcodeszzer
  • 916
  • 1
  • 8
  • 27
1
vote
0 answers

Parallel Array duplication findings and adding them

So I am struggling with writing one piece of code that will remove the duplicates from an parallel array. the file will be read then processed using two arrays but that's easy the part which i cannot figure out is for example when i have numbers…
uszy123345
  • 43
  • 9
1
vote
3 answers

Return values from parallel arrays and use those values in later functions

I am at a loss. I have tried several things and have 90% of the program working. In fact, it compiles and runs fine. My output is very bizarre characters where the letter grade is supposed to be. Our textbook does not offer examples with things…
CProject
  • 29
  • 4
1
vote
1 answer

How do I copy elements in a parallel array into a new parallel array with no duplicates in Java?

Hi guys I'm having a problem getting the right output for an assignment. I am looking for a way to copy a set of elements from one parallel array (which contains a string--int) to the other with no duplicate value. For example: I have these set of…
Oluwatosin
  • 170
  • 2
  • 11
1
vote
3 answers

How to remove duplicates from a parallel array in Java?

So, I started learning Java and was wondering how parallel arrays of string and int type could be stored exactly once from the source arrays. For example, I have two arrays parallel to each other, one stores the Phone number as a string and the…
ekeith
  • 644
  • 1
  • 10
  • 33
1
vote
2 answers

How do I add user input to parallel arrays in java?

This is the code I have now and it is completely butchered. I am having issues try to allow user input of a String and two doubles to go into 3 parallel arrays and then save to a .txt file. I can not figure out what is wrong could someone please…
DarthKiro
  • 31
  • 3
1
vote
3 answers

C++ Is parallel array a defined structure

Simple question: For my assignment I am asked to count the words in a file and keep track of their frequency. I am to create a parallel int array for the frequency. Is a parallel array a special data structure, or does it simply mean I am creating…
user3159071
1
vote
5 answers

Sort a parallel array using Arrays.sort()

Is it possible to sort an array using Arrays.sort() and thereafter have another related array positioned the same as the sorted array for example: String arrNames[] = new String[5]; String arrCellNo[] = new String[arrNames.length]; …
Ayvadia
  • 339
  • 1
  • 4
  • 19
1
vote
2 answers

Quick Search out of bounds of array and confusing array behaviour

I'm having multiple problems with my program (C#.NET) and have no idea what's causing them. The program is intended to sort a list of names and birthdays (formatted first name,last name,DD/MM/YYYY) in ascending and descending order by first name,…
user1576628
  • 792
  • 3
  • 8
  • 25
1
vote
3 answers

Side by Side display of parallel arrays in java

I'm quite new to java and I've written the code to display the values of the following parallel arrays: short[] Years = {1995, 1997, 1998,1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012}; String[] Months =…
user2297518
  • 35
  • 1
  • 3
  • 8
0
votes
1 answer

How to sort a parallel array to get the greatest and smallest value

I have two parallel arrays. one is type String and the other, type int. I want to sort them in ascending order while maintaining data consistency, keeping them parallel, to get the entry with the greatest int value and the entry with the int lowest…
0
votes
1 answer

How to return true or false with message inside the bool method for parallel array C#?

Note: I am learning to use the arrays. The issue with my bool method for the parallel array is that I want to return true or false with a message for balance being empty (equal to 0.00 in double data type) or not (return false). I got the result…
user19888755
0
votes
0 answers

Creating array, but every new value writes over the previous one

I've got a project due tomorrow I'm having trouble with. I'm new to programming and I'm building a project for school using parallel arrays. When I access my AddItem method from my main, it will write over the previous method call every time. If you…
CheckDeck
  • 5
  • 3
0
votes
3 answers

Parallel Arrays in C++

Trying to create a program that takes a coffee flavor add-in and checks if it's valid using an array. If valid it uses the array index to gather price information. I managed to write the code below, but it only works for 1 iteration. How can alter…
Leo
  • 51
  • 6