Skip to main content

Sorting Algorithms


Java Implementation for Sortings:

Bubble Sort:

import java.util.Scanner;
public class BubbleSort {
      public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("input size");
int n = scan.nextInt();
int[] ar = new int[n];
System.out.println("input elements");
for (int i = 0; i < ar.length; i++) {
ar[i] = scan.nextInt();
}
bubbleSort(ar);
for (int i = 0; i < ar.length; i++) {
System.out.print(ar[i]+"\t");
}
System.out.println();
scan.close();
}
private static void bubbleSort(int[] ar) {
// TODO Auto-generated method stub
int temp = 0;
for (int i = 0; i < ar.length; i++) {
for (int j = 1; j < (ar.length-i); j++) {
if(ar[j-1]>ar[j]){
temp = ar[j-1];
ar[j-1] = ar[j];
ar[j] = temp;
}
}
        }
}
}


Insertion Sort:

import java.util.Scanner;
public class InsertionSort {
    public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("input size");
int n = scan.nextInt();
int[] ar = new int[n];
System.out.println("input elements");
for (int i = 0; i < ar.length; i++) {
ar[i] = scan.nextInt();
}
insertionSort(ar);
for (int i = 0; i < ar.length; i++) {
System.out.print(ar[i]+"\t");
}
System.out.println();
scan.close();
}
private static void insertionSort(int[] ar) {
int key,j;
for (int i = 1; i < ar.length; i++) {
key = ar[i];
j=i-1;
while(j>=0 && ar[j]>key){
ar[j+1] = ar[j];
j--;
}
ar[j+1] = key;
}
}
}

Comments

Popular posts from this blog

Unshackling the 65mm Format: Inside the ARRI ALEXA 265

  Introduction If you’ve ever tried to shoot dynamic, kinetic movement with a 65mm digital cinema camera, you know the physical toll it takes. Hauling a 10.5-kilogram brain around requires specialized remote heads, heavy-duty stabilization, and an operator with iron shoulders. The sheer physics of large-format glass and massive sensor blocks historically meant sacrificing agility for image quality. Directors had to choose: do we want the immersive, medium-format aesthetic, or do we want to move fast in tight locations? The ARRI ALEXA 265 eliminates that compromise entirely. By stripping the 65mm form factor down to a staggering 3.3 kilograms and injecting the absolute cutting-edge of REVEAL Color Science, ARRI hasn’t just updated a camera—they have fundamentally altered how and where we can shoot large format. Let's break down why this is a seismic shift for visual creators. The Physics of Shrinking 65mm The most immediate shock when looking at the ALEXA 265 is the footprint. It i...

The Only Linear Light You’ll Ever Need? An In-Depth Look at the ARRI Omnibar

  Introduction We’ve all been there: you’re trying to hide a tube light in a tight corner, but the diffusion is too wide and spills everywhere. Or worse, you’re shooting in the rain, and your "weather-resistant" gear starts flickering. For too long, linear lighting has felt like a compromise between portability and professional-grade reliability. ARRI just ended that compromise. The Omnibar isn't just a response to the "tube light" trend; it’s a surgical tool designed to solve the most frustrating problems we face on set. Advanced Optics: Changing the Quality of Light Most linear lights give you one look: soft and wide. The Omnibar flips the script with a magnetic mounting system. By swapping the Round Diffuser for the Intensifier , you can tighten the beam to 60° and gain 50% more output. This means you can actually use a linear light as a punchy key or a controlled rim light without needing massive barn doors or honeycombs. Rugged Reliability and "Infi...

The Vespid Prime Manifesto: Why This is the Only Lens Set Your Indie Kit Needs

  Introduction You’ve spent months saving for that 8K full-frame sensor, but your images still look like high-resolution home movies. The problem isn't your camera; it's the glass. Most "affordable" lenses are just repurposed stills optics—clinically sharp, mechanically frustrating, and devoid of soul. On a fast-paced set, fighting with inconsistent gear positions and "breathing" focus is a recipe for a ruined production. Enter the DZOFILM Vespid Primes : the lenses designed to bridge the gap between high-end optical character and the budget realities of the modern filmmaker. The Beauty of the 16-Blade Iris In the cinema world, bokeh isn't just about "blurry backgrounds"—it’s about the quality of the out-of-focus highlights. Most budget lenses use 7 or 9 blades, resulting in "stop-sign" shaped bokeh when you close the aperture. The Vespids feature a massive 16-blade iris construction. This ensures that even at T5.6 or T8, your specula...