View Single Post
  #2   Spotlight this post!  
Unread 25-07-2010, 14:29
buildmaster5000 buildmaster5000 is offline
Trying to program the swerve drive
AKA: Alex
FRC #2421 (Rolling Thunder Robotics)
Team Role: Alumni
 
Join Date: May 2009
Rookie Year: 2009
Location: Northern Virginia
Posts: 207
buildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud of
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]+" ");
      }
   }
__________________
-Alex



2010 Washington DC Regional: Engineering Excellence Award