|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#2
|
|||
|
|||
|
Re: comparing integer lists
Is this LabView, Java or C++??
In Java (the only language I know), I would use nested for loops that would compare an element in the first array wiht each element in the second array. An example is below, where any number that is found in the other array is changed to -1. Code:
public class ArraySort
{
public static void main(String[]args)
{
int[] num1={1,3,4,5,6,8,10,15,19,20,55,99,100,115,156,205};
int[] num2={0,2,3,4,6,7,10,19,20,45,55,65,100,156,200,256};
//check for equal variables, if one is found, set element to -1
for(int x=0; x<num1.length; x++)
{
for(int a=0; a<num2.length; a++)
if(num1[x]==num2[a])
{
num1[x]=-1;
num2[a]=-1;
}
}
//print the arrays
for(int x=0; x<num1.length; x++)
System.out.print(num1[x]+" ");
System.out.println();
for(int x=0; x<num2.length; x++)
System.out.print(num2[x]+" ");
}
}
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Should we really be comparing Breakaway to soccer? | XaulZan11 | Rules/Strategy | 9 | 13-02-2010 15:22 |
| Merging/Comparing LabVIEW VIs | Terry Sherman | NI LabVIEW | 7 | 30-08-2009 10:30 |
| Comparing Sensor Readings in NQC | ZACH P. | Programming | 5 | 30-08-2003 17:33 |
| Integer Number | powercat | Programming | 2 | 18-02-2003 11:26 |
| Spreadsheet comparing ALL First motors | Nuts4FIRST | Motors | 0 | 08-01-2002 09:20 |