Krivalar Tutorials 
Krivalar Tutorials

Algorithm/Steps to sort a list or array of "N" numbers in ascending order:

  • Get the length of array. That is, the count of numbers to be sorted
  • Iterate through the numbers starting from first to the last
  • Swap 1st and 2nd number if the 1st number is greater. Swap 2nd and 3rd number if the 2nd number is greater, and so on until the last 2nd numbers are sorted
  • Previous step moves the greatest number to the last
  • The above 3 steps are repeated n number of times. Greater numbers keep moving to the right for each repetitive iteration.
  • Once all the repetitive iterations are complete, all the numbers are in ascending order

public class SortNumbersAscendingOrder {

	public static void main(String[] args) {
		int numbers[] = { 56,4,7,8,34,78,12,57,78,98,94,89999,1,56,8};
		int temp=0;
		int length = numbers.length;
		for(int i=0; i<length-1; i++) {
			for(int j=0; j<length-1; j++) {
				if(numbers[j]>numbers[j+1]) {
					temp = numbers[j];
					numbers[j] = numbers[j+1];
					numbers[j+1] = temp;
				}
			}
		}

		for(int i=0; i<numbers.length; i++) {
			System.out.print("" + numbers[i] );
			if(i<numbers.length-1) {
				System.out.print("," );
			}
		}
	}

}


























Searching using Binary Search Tree