Array in deascending order
Hello ...
if I have the following array:
static float [] in1 = { 0,0,0,80,0,0,100,0,0,90,0,0,70,60};
first I want to sort it so I will have as the following array {100,90,80,70,60,0,0,0,0,0,0,0,0,0}
Then I want an array of the positions of the first ordered values in the original array
I mean that I must have the following
{7,10,4,13,14,0,0,0,0,0}
How can I
1.sort the array (in deascending order)
2.build an array of the positions of the first 10 ordered value (its position in the original array
this is a simple way
O(n^2)
import java.util.*;
public class AT {
static float [] in1 = { 0,0,0,80,0,0,100,0,0,90,0,0,70,60};
public static void main(String [] arg) throws Exception {
float [] a = (float[]) in1.clone();
int [] pos = new int [a.length];
Arrays.sort(a);
for(int j=0; j<a.length/2; j++) {
float tmp = a[j];
a[j]=a[a.length-(j+1)];
a[a.length-(j+1)]=tmp;
for(int j=0; j<a.length; j++) {
while(pos[j]<in1.length && in1[pos[j]]!=a[j])
pos[j]++;
System.out.println(a[j]+" "+pos[j]);
}
Similar Messages
-
Sorting a two dimensional array in descending order..
Guy's I'm a beginning Java programmer. I've been struggling with finding documentation on sorting a two dimensional primitive array in descending order.. The following is my code which goes works, in ascending order. How do I modify it to make the list write out in descending order?
class EmployeeTable
public static void main(String[] args)
int[][] hours = {
{2, 4, 3, 4, 5, 8, 8},
{7, 3, 4, 3, 3, 4, 4},
{3, 3, 4, 3, 3, 2, 2},
{9, 3, 4, 7, 3, 4, 1},
{3, 5, 4, 3, 6, 3, 8},
{3, 4, 4, 6, 3, 4, 4},
{3, 7, 4, 8, 3, 8, 4},
{6, 3, 5, 9, 2, 7, 9}};
int [] total = new int [hours.length];
for (int i = 0; i < hours.length ; i++){
for (int j = 0; j < hours.length ; j++){
total[i] += hours[i][j];
int[] index = new int[hours.length];
sortIndex(total, index);
for (int i = 0; i < hours.length; i++)
System.out.println("Employee " + index[i] + " hours are: " +
total[i]);
static void sortIndex(int[] list, int[] indexList) {
int currentMax;
int currentMaxIndex;
for (int i = 0; i < indexList.length; i++)
indexList[i] = i;
for (int i = list.length - 1; i >= 1; i--) {
currentMax = list[i];
currentMaxIndex = i;
for (int j = i - 1; j >= 0; j--) {
if (currentMax < list[j]) {
currentMax = list[j];
currentMaxIndex = j;
// How do I make it go in descending order????
if (currentMaxIndex != i) {
list[currentMaxIndex] = list[i];
list[i] = currentMax;
int temp = indexList[i];
indexList[i] = indexList[currentMaxIndex];
indexList[currentMaxIndex] = temp;Bodie21 wrote:
nclow all you wrote was
"This looks to me like a homework assignment that you're asking us to solve for you. Your description of what it does isn't even correct. It doesn't sort a 2d array.
You would probably elicit better help if you could demonstrate that you've done some work and have something specific that you don't understand."
To me that sounds completely sarcastic. You didn't mention anything constructive besides that.. Hence I called you a male phalic organ, not a rear exit...Bodie21, OK, now you've got 90% of us who regularly contribute to this forum thinking your the prick. Is that what you wanted to do? If so, mission accomplished. Many will be looking for your name next time you ask for help. Rude enough for you? -
Trying to print the date arrays in reverse order....
Hi,
I'm trying to print the dates in the arrays in reverse order using the for loop, but its not working and i think ive got something in the wrong order perhaps the constructor or method. Or do i need to define 'a', because i tried it and i couldn't unless, probably because i was putting the wrong code for it.
Thanks for your help
public class Array
public static void main(String[] args)
a[0] = new Date(2, " January ", 2005)
a[1] = new Date(3, " February ", 2005)
a[2] = new Date(21, " March ", 2005)
a[3] = new Date(28, " April ", 2005)
printDate();
class Date
public int day;
public String month;
public int year;
public Date(int d, String m, int y)
day = d;
month = m;
year = y;
public void printDate()
for (int i = a.length - 1; i >= 0; i--)
System.out.println(a);I don't see where this 'a' variable is declared anywhere, so what did you expect it to do? Also, you can't just call Date's printDate method from your Array class like that. You really need to start with the java tutorials or take a course. The forums aren't going to effectively teach you the very basics.
-
Sorting a String Array in alpha order (Using ArrayList)
Hello all!
I am pretty new to Java and am trying to do a, seemingly, simple task; but cannot get the syntax right. I am trying to sort an ArrayList in aplha order based off of the variable String Product. Any help would be awesome!
First Class:
//This program stores all of the variables for use in Inventory.java
public class Vars {
// defining all variables
private String product;
private String prodCode;
private double price;
private double invCount;
// Begin listing getters for class
public Vars(String product) {
this.product = product;
public String getProdCode() {
return prodCode;
public String getProduct() {
return product;
public double getPrice() {
return price;
public double getInvCount() {
return invCount;
// Declaring the total variable
public double total() {
return invCount * price;
// Begin listing setters for variables
public void setProduct(String product) {
this.product = product;
public void setProdCode(String prodCode) {
this.prodCode = prodCode;
public void setInvCount(double invCount) {
this.invCount = invCount;
public void setPrice(double price) {
this.price = price;
Second Class:
//This program will use the variables stored in Vars.java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Inventory {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
//defining and declaring local variables
String exit;
int counter;
double gtotal;
exit = "exit";
counter = 0;
gtotal = 0;
//beginning message and beginning of the loop
System.out.print("Welcome to the Inventory Contol System\nPlease enter the Product name: ");
System.out.println();
System.out.println("When finished entering in the data, please enter EXIT in place of Product name.");
String name = input.next();
List<Vars> var = new ArrayList<Vars>(); //creating arraylist object
//loop while exit is not entered, exit loop once exit is typed into product variable
while (name.compareToIgnoreCase(exit) != 0) {
Vars vars = new Vars(name); //calling Vars methods
counter = counter ++;
System.out.println("Please enter the Product Code: ");
vars.setProdCode(input.next());
System.out.println("Inventory Count: ");
vars.setInvCount(input.nextDouble());
//Making sure that the value entered is a positive one
if(vars.getInvCount() < 0){
System.out.println("Please enter a positive number: ");
vars.setInvCount(input.nextDouble());
System.out.println("Price per product:");
vars.setPrice(input.nextDouble());
//Making sure that the value entered is a positive one
if(vars.getPrice() < 0) {
System.out.println("Please enter a positive number: ");
vars.setPrice(input.nextDouble());
System.out.println("Please enter the next Product name, or enter EXIT: ");
name = input.next();
gtotal += vars.total(); //calculation for Grand Total of all products entered
var.add(vars);
static void slectionSort(int[] product) {
for (int lastPlace = product.length-1; lastPlace > 0; lastPlace--) {
int maxLoc = 0;
for (int j = 1; j <= lastPlace; j++) {
if (product[j] > product[maxLoc]) {
maxLoc = j;
int temp = product[maxLoc];
product[maxLoc] = product[lastPlace];
product[lastPlace] = temp;
//Sorting loop function will go here, before the information is displayed
//Exit message and array list headers
System.out.print("Thank you for using the Inventory program.\nHave a wonderful day.\n");
System.out.printf("Code\tProduct\tCount\tPrice\tTotal\n");
System.out.println();
//For loop to display all entries via an ArrayList
for (Vars vars : var) {
System.out.printf("%5s\t%5s\t%.01f\t$%.02f\t$%.02f\n\n", vars.getProdCode(),
vars.getProduct(), vars.getInvCount(), vars.getPrice(),vars.total());
//Displays the amount of entries made and Grand Total of all products entered
System.out.println();
System.out.printf("The number of products entered is %d\n", var.size());
System.out.printf("The Grand Total cost for the products entered is $ %s\n", gtotal);
System.out.println();
}go through below links, you can easily understand how to sort lists.
http://www.onjava.com/lpt/a/3286
http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html
http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-sort.html -
Arrange Array in ascending order by date
Kindly help me sort out the order by problem.
I have a date array which goes like;
12/3/2012
11/3/2012
12/5/2012
12/8/2012
12/6/2012
12/12/2012
12/10/2012
12/17/2012
I need to arrange it in ascending order, like
11/3/2012
12/3/2012
12/5/2012
12/6/2012
12/8/2012
12/10/2012
12/12/2012
12/17/2012
Please help.
Thank you in advance.
Regards
Grugh Mike
Success is Everything !!Grugh_Mike wrote:
is'nt there any easier method to sort a time array ?
It's a lot easier than trying to manipulate the strring into yyyy/dd/mm format and sorting alphabetically.
Bill
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all. -
As3 (Flash CS4) Actionscript array/mc display order
Hi there,
Im trying to amend this actionsscript so the rollover part appears above the image gallery. Ive tried everything i can think of and the rollover appears below the images.
If anyone can help I would be eternally grateful!
Here is the actionscript...
import fl.transitions.Tween;
import fl.transitions.easing.*;
var filename_list = new Array();
var url_list = new Array();
var url_target_list:Array = new Array();
var title_list = new Array();
var description_list = new Array();
var i:Number;
var tn:Number = 0;
var no_of_column:Number = 8;
var no_of_row:Number = 4; // number of rows showing at a time
var no_of_extra_row:Number;
var scale_factor:Number = 0.8;
var tween_duration:Number = 0.6;
var new_row:Number = 0;
var total:Number;
var flashmo_xml:XML = new XML();
var folder:String = "thumbnails/";
var xml_loader:URLLoader = new URLLoader();
xml_loader.load(new URLRequest("azwebgallery.xml"));
xml_loader.addEventListener(Event.COMPLETE, create_thumbnail);
var thumbnail_group:MovieClip = new MovieClip();
stage.addChild(thumbnail_group);
thumbnail_group.x = tn_group.x + 20;
var default_y:Number = thumbnail_group.y = tn_group.y + 60;
thumbnail_group.mask = tn_group_mask;
tn_group.visible = false;
fm_previous.visible = false;
fm_next.visible = false;
tn_title.text = "";
tn_desc.text = "";
tn_url.text = "";
function create_thumbnail(e:Event):void
flashmo_xml = XML(e.target.data);
total = flashmo_xml.thumbnail.length();
no_of_extra_row = Math.floor(total / no_of_column) - no_of_row;
for( i = 0; i < total; i++ )
filename_list.push( flashmo_xml.thumbnail[i][email protected]() );
url_list.push( flashmo_xml.thumbnail[i][email protected]() );
url_target_list.push( flashmo_xml.thumbnail[i][email protected]() );
title_list.push( flashmo_xml.thumbnail[i][email protected]() );
description_list.push( flashmo_xml.thumbnail[i][email protected]() );
load_tn();
function load_tn():void
var pic_request:URLRequest = new URLRequest( folder + filename_list[tn] );
var pic_loader:Loader = new Loader();
pic_loader.load(pic_request);
pic_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_loaded);
tn++;
function on_loaded(e:Event):void
if( tn < total )
load_tn();
else
fm_previous.visible = true;
fm_next.visible = true;
fm_previous.addEventListener( MouseEvent.CLICK, to_previous );
fm_next.addEventListener( MouseEvent.CLICK, to_next );
stage.addEventListener(MouseEvent.MOUSE_WHEEL, on_wheel );
var flashmo_bm:Bitmap = new Bitmap();
var flashmo_mc:MovieClip = new MovieClip();
flashmo_bm = Bitmap(e.target.content);
flashmo_bm.x = - flashmo_bm.width * 0.5;
flashmo_bm.y = - flashmo_bm.height * 0.5;
flashmo_bm.smoothing = true;
var bg_width = flashmo_bm.width + 10;
var bg_height = flashmo_bm.height + 10;
flashmo_mc.addChild(flashmo_bm);
flashmo_mc.graphics.beginFill(0xFFFFFF);
flashmo_mc.graphics.drawRect( - bg_width * 0.5, - bg_height * 0.5, bg_width, bg_height );
flashmo_mc.graphics.endFill();
flashmo_mc.name = "flashmo_" + thumbnail_group.numChildren;
flashmo_mc.buttonMode = true;
flashmo_mc.addEventListener( MouseEvent.MOUSE_OVER, tn_over );
flashmo_mc.addEventListener( MouseEvent.MOUSE_OUT, tn_out );
flashmo_mc.addEventListener( MouseEvent.CLICK, tn_click );
flashmo_mc.scaleX = flashmo_mc.scaleY = scale_factor;
flashmo_mc.x = thumbnail_group.numChildren % no_of_column
* ( bg_width + 2 ) * scale_factor;
flashmo_mc.y = Math.floor( thumbnail_group.numChildren / no_of_column )
* ( bg_height + 2 ) * scale_factor;
thumbnail_group.addChild(flashmo_mc);
function tn_over(e:MouseEvent):void
var mc:MovieClip = MovieClip(e.target);
var s_no:Number = parseInt(mc.name.slice(8,10));
thumbnail_group.addChild(mc);
new Tween(mc, "scaleX", Elastic.easeOut, mc.scaleX, 1, tween_duration, true);
new Tween(mc, "scaleY", Elastic.easeOut, mc.scaleY, 1, tween_duration, true);
tn_title.text = title_list[s_no];
tn_desc.text = description_list[s_no];
tn_url.text = url_list[s_no];
function tn_out(e:MouseEvent):void
var mc:MovieClip = MovieClip(e.target);
new Tween(mc, "scaleX", Strong.easeOut, mc.scaleX, scale_factor, tween_duration, true);
new Tween(mc, "scaleY", Strong.easeOut, mc.scaleY, scale_factor, tween_duration, true);
tn_title.text = "";
tn_desc.text = "";
tn_url.text = "";
function tn_click(e:MouseEvent):void
var mc:MovieClip = MovieClip(e.target);
var s_no:Number = parseInt(mc.name.slice(8,10));
navigateToURL(new URLRequest(url_list[s_no]), url_target_list[s_no]);
function to_previous(e:MouseEvent):void
if( new_row < 0 )
new_row++;
new Tween( thumbnail_group, "y", Strong.easeOut, thumbnail_group.y, default_y + new_row * 100, tween_duration, true );
function to_next(e:MouseEvent):void
if( Math.abs(new_row) < no_of_extra_row )
new_row--;
new Tween( thumbnail_group, "y", Strong.easeOut, thumbnail_group.y, default_y + new_row * 100, tween_duration, true );
function on_wheel(e:MouseEvent):void
if( e.delta > 0 )
new_row++;
else
new_row--;
if( new_row >= 0 )
new_row = 0;
else if( new_row < - no_of_extra_row )
new_row = - no_of_extra_row;
new Tween( thumbnail_group, "y", Strong.easeOut, thumbnail_group.y, default_y + new_row * 100, tween_duration, true );Anyone got any odeas on how I can get this to work?
Looking at the code this part is the part which i need to appear on top of everything else.
function tn_over(e:MouseEvent):void
var mc:MovieClip = MovieClip(e.target);
var s_no:Number = parseInt(mc.name.slice(8,10));
thumbnail_group.addChild(mc);
new Tween(mc, "scaleX", Elastic.easeOut, mc.scaleX, 1, tween_duration, true);
new Tween(mc, "scaleY", Elastic.easeOut, mc.scaleY, 1, tween_duration, true);
tn_title.text = title_list[s_no];
tn_desc.text = description_list[s_no];
tn_url.text = url_list[s_no]; -
API which can sort array in decending order
hi all,
i just want to know is there any API available in Java which can sort an array of integers in desending orderhttp://www.google.co.uk/search?hl=en&q=java+quicksort+API&btnG=Search&meta=
will bring this right up:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Arrays.html -
how can i sort the numbers in rank order i.e. there are 5 random numbers displayed 1 5 2 4 3. i would like to sorth these numbers into rank order 1 2 3 4 5
import java.io.*;
public class random {
public static void main(String args[]) {
try {
PrintWriter out = new PrintWriter(new FileWriter("random.txt"));
java.util.Random rand = new java.util.Random();
for (int i = 0; i < 20; i++) {
out.println(rand.nextInt(10));
out.close();
} catch (IOException ioe) {
ioe.printStackTrace();
try {
FileReader fr = new FileReader("random.txt");
int i;
while((i=fr.read()) != -1) {
System.out.print((char)i);
fr.close();
catch(Exception e) {
System.out.println("Exception \n" + e);
}can a mod close/delete this topic!!!
do not reply to this one!!! -
Displaying Array Position not working in case of descending Order?
Hi,
I need to display the array position of the sorted array in Descending order. Here is my code.
int[] in = {5,3,2,7};
int[] newArr = new int[in.length];
int[] na = new int[in.length];
//copying into a new array
for(int i=0;i<in.length;i++){
newArr[i] = in;
// code for descending order
for(int j=0;j<in.length;j++){
Arrays.sort(in);
na[j] = in[in.length-(1+j)];
}the sorted array will be will be {7,5,3,2} now according to this i need to display the array position of the sorted array which should be {3,0,1,2} i tried to compare newArr[i] with na[j] but am not gettin the result that i should be getting the same comparison is working in case of Ascending Order but not descending. Any suggestions or help will be appreciated.
Thanks and regards.hi,
what you are doing is correct only, do not put sort method inside the for loop
and postion is correct also
int[] in = {5,3,2,7};
int[] newArr = new int[in.length];
int[] na = new int[in.length];
//copying into a new array
for(int i=0;i<in.length;i++){
newArr[i] = in;
Arrays.sort(in);
// code for descending order
for(int j=0;j<in.length;j++){
na[j] = in[(in.length-1)-j];
System.out.println("Val --> "+na[j]);
System.out.println("Position --> "+j); -
Applescript - ID - CS3 or CS4 - create array containing front/back order of objects?
Hi all,
I'm looking for ideas of how to do this: create a layer for each object in the document, then move each object onto it's own layer — and preserve front/back arrangment. In other words, 10 objects = 10 layers, without changing stacking order.
So far I've got it creating unique layers and moving objects onto each. . .but i'm looking for the most efficient way to have it handle the original stacking order.
I suppose i can start learning how to build an array, then re-order it by index (which i understand indicates front/back), and then create layers following that order? If that's the best way, I'd LOVE some direction on how to code that. Or, if there a more elegant solution?
Thanks for any help!
CS3 is ideal but can use CS4 if necessary (or CS5 if there's some killer function in there)It's a vertical imposition script. Items from the top half of each page are moved to a different page (using a temp page as a staging area), then pages are reshuffled. Here is the script:
tell application "Adobe InDesign CS5"
set myDocument to active document
save myDocument
set fp to file path of myDocument
set DocName to name of myDocument
if DocName ends with ".indd" then
set DocName to characters 1 thru -6 of DocName as string
end if
set myFileName to fp & DocName & "-imposed.indd" as string
tell myDocument
repeat with i from 2 to 7
set myPage1 to page i
set myPage2 to page (16 - i)
set myTempPage to page 15
set myItems1 to (every item of all page items of myPage1 whose (class is in {rectangle, oval, polygon, graphic line, text frame}) and (parent's class is spread))
set myItems2 to (every item of all page items of myPage2 whose (class is in {rectangle, oval, polygon, graphic line, text frame}) and (parent's class is spread))
repeat with myPageItemCounter from (count myItems1) to 1 by -1
set myitem to item myPageItemCounter of myItems1
set locked of myitem to false
set mybounds to geometric bounds of myitem
if item 3 of mybounds < 52.5 then
tell myitem to move to myTempPage
tell myitem to move to {item 2 of mybounds, item 1 of mybounds}
end if
end repeat
repeat with myPageItemCounter from (count myItems2) to 1 by -1
set myitem to item myPageItemCounter of myItems2
set locked of myitem to false
set mybounds to geometric bounds of myitem
if item 3 of geometric bounds of myitem < 52.5 then
tell myitem to move to myPage1
tell myitem to move to {item 2 of mybounds, item 1 of mybounds}
end if
end repeat
set myTempItems to (every item of all page items of myTempPage whose (class is in {rectangle, oval, polygon, graphic line, text frame}) and (parent's class is spread))
repeat with myPageItemCounter from (count myTempItems) to 1 by -1
set myitem to item myPageItemCounter of myTempItems
set mybounds to geometric bounds of myitem
tell myitem to move to myPage2
tell myitem to move to {item 2 of mybounds, item 1 of mybounds}
end repeat
end repeat
delete page 15
move last page to after page 1
move last page to after page 3
move last page to after page 5
move last page to after page 7
move last page to after page 9
move last page to after page 11
save myDocument to myFileName
end tell
end tell -
Descending order for arrays by name
Hi, thank you to all the people who previously helped me before....
Is there a way to sort an array in decending order by name?
I was trying to figure out what to do but this is what i have so far
double [] Salary = new double [10];
String [] Names = new String [10];
int i, j;
for ( i = 0; i < 10; i++)
System.out.print(" Name is: " + Names);
Names[i] = ReadInput.StringRead(); //asks user for Salry
System.out.println(" Salary is: " + Salary[i] );
Salary[i] = ReadInput.readDouble(); //asks user for Names
for (j=0; j < 10; j++)
System.out.println(Names[j] + ": " + Salary[j]);Smckee6452, thank you for helping me.....
i think i am getting close, but the sorting part (descending by names)part of the code is not working too well
did i miss something??
public class Compare {
public Compare() {
double [] Salary = new double [10];
String [] Names = new String [10];
String nameTemp = new String();
double salaryTemp = 0.0;
for (int i = 0; i < 10; i++)
System.out.print(" Name is: " + Names);
Names[i] = ReadInput.StringRead(); //asks user for Salry
System.out.println(" Salary is: " + Salary[i] );
Salary[i] = ReadInput.readDouble(); //asks user for Names
// for (int j=0; j < 10; j++)
// System.out.println(Names[j] + ": " + Salary[j]);
for (int i = 0; i < 9; i++)
for ( int j = 1; j < 10; j++)
{ //do compare and swapping in here
nameTemp = Names[i];
Names[i] = Names[j];
Names[j] = nameTemp;
salaryTemp = Salary[i];
Salary[i] = Salary[j];
Salary[j] = salaryTemp;
System.out.print(nameTemp);
System.out.println(salaryTemp); -
Order array by object variable
Hello !
I have an array which I'm looping through to get variables(as text) to display in dynamic text fields..
If possible I would like to sort the array into numeric order using "sTabArray[i].sHour". A variable of each of the array items..
Is there a way I can do this ? Maybe create a new array from the original one and then use that ??
for(i = 0; i < sTabArray.length; i++) {
var sMin:String = sTabArray[i].sMin;
var fMin:String = sTabArray[i].fMin;
var table_number:String = sTabArray[i].table_number;
var salle_number:String = sTabArray[i].salle_number;
printBox["horaires" + i].text = sTabArray[i].sHour + ":" + sMin + " à " + sTabArray[i].fHour + ":" + fMin;
printBox["evenement" + i].text = sTabArray[i].titre;
printBox["salle" + i].text = salle_number;
printBox["table_no" + i].text = table_number;
Many thanks in advance for you help
MartinsortOn
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#sortOn%28%29 -
Sorting an array of integers into ascending order
Today I decided to blow the cobwebs off my old laptop and see what I could remember from my Java days.
As a task for myself to see what I could remember, I decided to try and write a program that does the following:
- Declares an array of 4 integers
- Sorts the array into ascending order, from lowest to highest.
- Prints on screen the sorted array.
After an hour or so I finally cracked it, and ended up with a working program. Here she is:
public class Sorting_arrays_1
public static void main()
int [] array = {4,3,7,1};
//A variable used to help with swopping values
int temporary;
//finds the smallest number out of elements 0, 1, 2, and 3 of the array, then moves it to position 0
for (int count = 0; count<array.length;count++)
int smallestNumber = array[0];
if (array[count] < smallestNumber)
smallestNumber = array[count];
temporary = array[0];
array[0]=array[count];
array[count]=temporary;
//finds the smallest number out of elements 1, 2, and 3 of the array, then moves it to position 1
for (int count = 1; count<array.length;count++)
int smallestNumber = array[1];
if (array[count] < smallestNumber)
smallestNumber = array[count];
temporary = array[1];
array[1]=array[count];
array[count]=temporary;
//finds the smallest number out of elements 2 and 3 of the array, then moves it to position 2
for (int count = 2; count<array.length;count++)
int smallestNumber=array[2];
if (array[count] < smallestNumber)
smallestNumber = array[count];
temporary = array[2];
array[2]=array[count];
array[count]=temporary;
//prints the array in ascending order
for (int count=0; count<array.length;count++)
System.out.print(array[count] + " ");
}Could this code be simplified though? Maybe with a for loop?
I mean, it does the job, but it looks so clumbsy and inefficient... Imagine how much code I would need if I wanted to sort 1000 numbers..Use bubble sort if u want a quick fix
public static void bubbleSort(int [] a)
for(int i=0; i<a.length-1; i++)
for(int j=0; j<a.length-1-i; j++)
if(a[j]>a[j+1])
int temp = a[j];
a[j]=a[j+1];
a[j+1]=temp;
Or use Merge sort if u want better run time... ie.(N log N) -
Report Does Not Follow Select Column Order
Hi all,
Apex 2.2 on 10gXE
I always encounter this problem, the display column on report does not follow the select column sequence order in the "region source".
It is very tedious clicking the up/down arrow one-by-one in the "report attributes" especially if the display columns are plenty like 40 columns.
Is there a fix/patch or alternative tips for this bug?
Thanks a lot,
Edited by: 843228 on May 24, 2011 10:32 PMApex 2.2 on 10gXEStart by upgrading from this old unsupported version.
>
I always encounter this problem, the display column on report does not follow the select column sequence order in the "region source".
It is very tedious clicking the up/down arrow one-by-one in the "report attributes" especially if the display columns are plenty like 40 columns.
Is there a fix/patch or alternative tips for this bug?
>
This is not a bug. APEX maintains the original column order of the report. This avoids problems downstream in areas like the processing of <tt>g_fnn</tt> arrays in declarative tabular forms, where the assigned arrays are column-order dependent.
APEX 4.x fixes column ordering bugs that could lead to report corruption, and includes drag-and-drop column ordering in the new tree view in addition to the up/down arrow re-ordering.
If you really want column order to follow that in the source query, the workaround is to create a new report using the modified query. -
How do I create an array with variables also splits words in a txtfile?
Hello guys,
I made a script that reads a text file.
function readMyFile()
var myFile=File(app.activeDocument.filePath + "/LareLog.txt");
if (myFile.exists)
myFile.open("r");
var Temps = myFile.read();
alert (Temps); // message the content
var nyRad=("\n"); // break the line
textArr=Temps.split(nyRad);
alert(textArr); // message the content with all info on new lines ("\n");
myFile.close();
my textfile contains:
~/Desktop/3.indd ,Thu Mar 20, 2014, 11:26:34 , GMT+0100
I wonder how do I sort the content in array
in this order, also creates variables for each string.
var= string 1[~/Desktop/3.indd]
var2=string 2[11:26:34]
var3=string 3[11:26:34]
var4=string 4[2014]
var5=string 5 [GMT+0100]
Thank you in advance people.Hmmh?
Jump_Over said it before: „… are stored as separate array's elements …“ in your [textArr]
So you can create now variables on this way:
var string_1 = textArr[0]; // and so on
alert(string_1);
See Java Scripting reference for more examples how to use Arrays.
Maybe you are looking for
-
I have a requirement to create a company code that will reside in Puerto Rico. I assigned this company code to the country PR. As I move towards the configuration of the payment methods within country PR I was wondering if I could use RFFOUS_C for
-
Status on RE:Reporting after many forte tasks run
-
Regarding the internal table data by using read table it_mard into wa_mard
hi, i am reading the internal table it_mard with key matnr . my code is like this. *loop at it_final into wa_final.* *wa_second-matnr = wa_final-matnr.* wa_second-bwart = wa_final-bwart. wa_second-bwtar = wa_final-bwtar. *read table it_mard into w
-
HT201210 Update ipad 1 from 5.1 to 5.1.1 - Server not responding
is the ipad software update server not responding at the moment, i have exhausted all the troubleshooting options, all i want to do is update or restore to 5.1.1??
-
All my files in my macbook pro is saved several times. How can I delete all the multiple copies easily?