FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   again resort..with code
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: again resort..with code  (Read 279 times)
Matthias
Guest
Email
again resort..with code
« on: Mar 3rd, 2004, 8:33pm »

I wanna sort the col2Array....but I would like to build a new array where I store the originale place of the pixel in the col2Array....so that I know...1st value in the sorted array was original the xth value in the col2Array.
 
Can somebody help me with this? Thanks a lot...Matthias
 
mysort(col2Array);
 
void mysort(int[] a) {
  int n = a.length;
  for (int i=0; i<n-1; i++) {
    for (int j=0; j<n-1-i; j++)
    if (brightness(a[j+1]) < brightness(a[j])) {  
 int tmp = a[j];    
 a[j] = a[j+1];
 a[j+1] = tmp;
    }
  }
 
}
 
benelek

35160983516098 WWW Email
Re: again resort..with code
« Reply #1 on: Mar 3rd, 2004, 11:01pm »

here's something you could do... but it depends what you want to use it for, as to how useful it would be.
 
this will give you an array of index numbers which map old locations within the sorted array to new locations.
 
Code:

int[] indexReference = mysort(col2Array);
 
//mysort() now returns an array of index numbers.
int[] mysort(int[] a) {
  int[] tempRef = new int[a.length];
  for(int i=0; i<a.length; i++) {
    tempRef[i]=i;
  }
  int n = a.length;
  for (int i=0; i<n-1; i++) {
    for (int j=0; j<n-1-i; j++)
    if (brightness(a[j+1]) < brightness(a[j])) {
 int tmp = a[j];
 int tmpI = tempRef[j];
 a[j] = a[j+1];
 a[j+1] = tmp;
 tempRef[j]=tempRef[j+1];
 tempRef[j+1]=tmpI;
    }
  }
  return tempRef;
}
 
Matthias
Guest
Email
Re: again resort..with code
« Reply #2 on: Mar 5th, 2004, 5:43am »

Thanks a lot benelek... I think I can use it...but I do something wrong. I tried to take an other picture and change the pixel so that they go in the other of the old Array.  
I have one pic and sort the Array. With the indexReference I still know where the location of the values in the sorted Array were in the original Array...and now I wanna tell to an other Array that it should order the values in the way my original Array was...how do I do that? Thanks a lot...
Matthias
 
Pages: 1 

« Previous topic | Next topic »