BUBBLE SORT PROGRAM USING JAVA In Bubble sort we compare two consecutive elements of an array, if first one element is greater than next one then swap them. The time complexity in worst and average case is O(n^2) while in best case is O(n) and the space complexity is O(1) . package bubbleSort; public class BubbleSort { public static void bubbleSort(int[] arr) { for(int i=0; i<arr.length; i++) { for(int j=i+1; j<arr.length; j++) { if(arr[i] > arr[j]) { // swap the numbers int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } } // main method public static void main(String[] args) { // declare and assign an unsorted array i...
Storage Class in C Programming (variable storage class) From compiler point of view, a variable name identify some physical location in any computer when a string of bits representing a variables value stored. There are basically two kind of location in computer where such values are stored - 1. CPU Registers 2. Main Memory It is variable storage class that determine in which of these two types of location, ...
Comments
Post a Comment