Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

bubbelsort

import java.util.*;

public class Sort{
//static Scanner sc=new Scanner(System.in);

public static void main(String []args){
    double [] lista ={6,3,8,1,5};
//skriv ut den osorterade arrayen
	/*	for(int i = 0; i < lista.length; i++){
			System.out.println(lista[i]+" ");
		}*/
		

bubbleSort(lista);
  //System.out.println(lista[i]+" ");
//skriv ut sorterad array
		for(int i = 0; i < lista.length; i++){
			System.out.println(lista[i]+" ");
		}



}


//bubbelsortering
	public static void bubbleSort(double data[]) {
		
		for(int m = data.length-1; m > 0; m--) {
			
			for(int n = 0; n < m; n++) {
				
				if(data[n] > data[n+1]) {
					double temp = data[n];
					data[n] = data[n+1];
					data[n+1] = temp;
				}
			}
		}
	}


//https://www.youtube.com/watch?v=RqfWvIsYmsc



}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.