diff --git a/sorting/OddEvenSort.java b/sorting/OddEvenSort.java new file mode 100644 index 00000000..bc16b9b7 --- /dev/null +++ b/sorting/OddEvenSort.java @@ -0,0 +1,65 @@ +class OddEven +{ + private long[] a; + private int nElems; + public OddEven(int max) + { + a = new long[max]; + nElems = 0; + } + public void insert(long value) + { + a[nElems] = value; + nElems++; + } + public void display() + { + for(int j=0; ja[i+1]) + swap(i,i+1); + for(j=1;ja[j+1]) + swap(j,j+1); + k++; + } + } + private void swap(int one, int two) + { + long temp = a[one]; + a[one] = a[two]; + a[two] = temp; + } +} +class OddEvenSort +{ + public static void main(String[] args) + { + int maxSize = 100; + OddEven arr; + arr = new OddEven(maxSize); + arr.insert(77); + arr.insert(99); + arr.insert(44); + arr.insert(55); + arr.insert(22); + arr.insert(88); + arr.insert(11); + arr.insert(00); + arr.insert(66); + arr.insert(33); + System.out.println("Before Sort : "); + arr.display(); + arr.oddEvenSort(); + System.out.println("After Sort : "); + arr.display(); + } +} \ No newline at end of file