🔒 Closed Java Sort while showing how it sorted.

Status
Not open for further replies.

Penpenqt69

Journeyman
Code:
 public static void main(String[] args) {
        // TODO code application logic here
        int temp,j, small, ctr,x,y,  input;
        System.out.print("Enter Lenght: ");
        Scanner In = new Scanner(System.in);
        input = In.nextInt();
        int myArray[] = new int[input];
        System.out.println("Input Numbers");
        for(x=0;x<input;x++){
            myArray[x]=In.nextInt();
        }
        for(y=0;y<myArray.length;y++){
            small = myArray[y];
            ctr = y;
            for(j=y+1;j<myArray.length;j++){
                if(myArray[j]>small);{
              small = myArray[j];
                ctr = j;
            }
            }
            temp=myArray[y];
            myArray[y]=small;
            myArray[ctr]=temp;
            for(ctr=0;ctr<myArray.length;ctr++){
                System.out.print(myArray[ctr]+"   ");
            }
            System.out.println("");
        }
        
        
    }
    
}


OUTPUT:

Enter Lenght: 5
Input Numbers
6
7
12
3
5

5 7 12 3 6
5 6 12 3 7
5 6 7 3 12
5 6 7 12 3
5 6 7 12 3

Ang gusto ko pa sanang gawi is ma sort sya in ascending while showing kung ano yung na ta-transpose. kaso ganyan po lumalabas
please po help me to fix this. THANK YOU!!!!~
 
Code:
 public static void main(String[] args) {
        // TODO code application logic here
        int temp,j, small, ctr,x,y,  input;
        System.out.print("Enter Lenght: ");
        Scanner In = new Scanner(System.in);
        input = In.nextInt();
        int myArray[] = new int[input];
        System.out.println("Input Numbers");
        for(x=0;x<input;x++){
            myArray[x]=In.nextInt();
        }
        for(y=0;y<myArray.length;y++){
            small = myArray[y];
            ctr = y;
            for(j=y+1;j<myArray.length;j++){
                if(myArray[j]>small);{
              small = myArray[j];
                ctr = j;
            }
            }
            temp=myArray[y];
            myArray[y]=small;
            myArray[ctr]=temp;
            for(ctr=0;ctr<myArray.length;ctr++){
                System.out.print(myArray[ctr]+"   ");
            }
            System.out.println("");
        }
      
      
    }
  
}


OUTPUT:

Enter Lenght: 5
Input Numbers
6
7
12
3
5

5 7 12 3 6
5 6 12 3 7
5 6 7 3 12
5 6 7 12 3
5 6 7 12 3

Ang gusto ko pa sanang gawi is ma sort sya in ascending while showing kung ano yung na ta-transpose. kaso ganyan po lumalabas
please po help me to fix this. THANK YOU!!!!~

uy klasmate ahahahaha , dito pala nanggagaling mga code mo ha. akala ko pa naman sariling gawa mo tlga yung mga pinapasa mo sa skul :ROFLMAO:
 
Iprint mo lang 'yung array, paps, kada iteration nung logic. So sa end nung loop, ipriprint mo 'yung array, para every time na magsort ay magpriprint ung nabago. Pwede mo ring lagyan ng conditional statement na icheck kung may nabago doon sa array bago iprint para magpriprint lang sya sa tuwing may change/nagsort talaga.
 
i remember yung assignment namin before parang ganito din yun..sorting algo..

we use delay kung an0 na yung status ng list..
tas tenetest namin kung ano ung mabilis na process..

btw maraming klase ng sorting if im correct bubble sort tung gamit mo..

may merge,heap,quick etc..
 
Status
Not open for further replies.

About this Thread

  • 10
    Replies
  • 624
    Views
  • 3
    Participants
Last reply from:
kaz050457

Trending Topics

Online now

Members online
1,127
Guests online
894
Total visitors
2,021

Forum statistics

Threads
2,275,014
Posts
28,960,008
Members
1,233,514
Latest member
Nixxie
Back
Top