Skip to main content

desending sort algo

...
double []test = new double []{88.6,88.9,-1,25,88.6};
int size = test.length;

System.out.println("*** un-sorted ***");
for (double d : test){
System.out.println(d);
}

// descending sort algo *************************************
int counter = 0;
int indexOfMax = 0;

// after each iteration of while, test[counter] should have the correct value
while (counter < size){
indexOfMax = counter; // assuming that test[counter] has the max value
// this loop finds the index of max value (stores in indexOfMax) from the test array starting from index counter+1
for(int i = counter+1; i < size; i++){
if (test[i]>test[indexOfMax]){
indexOfMax = i;
}
} // end of for loop -- now indexOfMax should have the max value

// swapping
double tmp = test[counter];
test[counter] = test[indexOfMax];
test[indexOfMax] = tmp;
counter++;
}
// end of algo *********************************************

System.out.println("*** sorted ***");
for (double d : test){
System.out.println(d);
}
...

Comments

Popular posts from this blog

Error validating server certificate / The certificate is not issued by a trusted authority

I was able to use SVN with ease (checkin, checkout, update code) until recently the SVN server went through some changes. I started to see the following on each SVN command: Error validating server certificate for 'https://svn.myserver.com:443':  - The certificate is not issued by a trusted authority. Use the    fingerprint to validate the certificate manually!  - The certificate hostname does not match. Certificate information:  - Hostname: de-v-svn  - Valid: from ...  - Issuer: I...  - Fingerprint: ... (R)eject, accept (t)emporarily or accept (p)ermanently? It worked fine when I selected  (p)ermanently but had to do it again next time I used  SVN command. Solution: Delete ~/.subversion folder. svn cleanup svn up

How to upload an artifact to maven remote repository?

If you want to deploy artifacts that were not build using maven, or which were build using maven but their POMs did not contains the deployment detials, then you need to deploy them using the following: mvn -e deploy:deploy-file -DgroupId=com.test.jpa -DartifactId=jpa-demo -Dversion=1.0.0 -Dpackaging=jar -Dfile=jpa-demo-1.0.0.jar -Durl=http://localhost:8080/archiva/repository/internal/ -DrepositoryId=reppoI d url: specifies the remote maven repository to where the jar is to be uploaded repositoryId: Id repository is secured, repositoryId is used to specify the credentials that are to be used for uploading. Repositories are defined in settings.xml. e.g. <servers>     <server>       <id>deploymentRepo</id>       <username>repouser</username>       <password>repopwd</password>     </server> </servers> Maven repository will return code 401 if credentials are missing or invalid. Better way is to use deploy p