diff --git a/Section B/CPW/datastructure/Bubble Sort/BubbleSort.java b/Section B/CPW/datastructure/Bubble Sort/BubbleSort.java new file mode 100644 index 0000000..05f9930 --- /dev/null +++ b/Section B/CPW/datastructure/Bubble Sort/BubbleSort.java @@ -0,0 +1,37 @@ +import java.util.Scanner; + +public class Bubble{ + + public static void main(String[] args){ + + int Numbers[]=new int[10]; + int N=10; + int outer,inner,temp; + Scanner input = new Scanner(System.in); + + System.out.println("Enter ten numbers for sorting:"); + for(outer=0;outer<10;outer++) //To get values from user + Numbers[outer]=input.nextInt(); + + + for(outer=1;outerNumbers[inner+1]) + { + temp=Numbers[inner]; + Numbers[inner]=Numbers[inner+1]; + Numbers[inner+1]=temp; + } + } + } + + System.out.println("Your numbers was ordered!") ; + + for(outer=0;outer<10;outer++) //To show the ordered numbers + System.out.print(Numbers[outer]+" "); + + + } +} \ No newline at end of file diff --git a/Section B/CPW/datastructure/Quick Sort/QuickSort.java b/Section B/CPW/datastructure/Quick Sort/QuickSort.java new file mode 100644 index 0000000..a726bde --- /dev/null +++ b/Section B/CPW/datastructure/Quick Sort/QuickSort.java @@ -0,0 +1,85 @@ +/*--------------------------------------------------- +This code copied from: +DATA STRUCTURES & ALGORITHMS IN JAVA + ROBERT LAFORE + SECOND EDITION + + +-----------------------------------------------------*/ +class ArrayIns{ +private long[] theArray; //ref to array theArray +private int nElems; //number of data items + + public ArrayIns(int max) //constructor + { + theArray =new long[max]; //create the array + nElems =0; + } + + public void insert(long value) //put elements into array + { + theArray[nElems] = value; //insert items + nElems++; //increament size + } + + public void display() //display array contents + { + System.out.print(" A= "); + for(int j=0;j 0 && theArray[--rightPtr] > pivot) + ; + + if(leftPtr>=rightPtr) //if pointers cross + break; //partition done + else //not crossed + swap(leftPtr,rightPtr); //swap elements + } + + swap(leftPtr,right); //restore pivot + return leftPtr; //return pivot location + + } + + public void swap(int dex1, int dex2) //swap two elements + { + long temp = theArray[dex1]; + theArray[dex1] = theArray[dex2]; + theArray[dex2] = temp; + } + +} \ No newline at end of file diff --git a/Section B/CPW/datastructure/Quick Sort/QuickSortApp.java b/Section B/CPW/datastructure/Quick Sort/QuickSortApp.java new file mode 100644 index 0000000..4a4bac4 --- /dev/null +++ b/Section B/CPW/datastructure/Quick Sort/QuickSortApp.java @@ -0,0 +1,20 @@ +class QuickSortApp +{ + public static void main(String[] args) + { + int maxSize = 16; //array maxSize + ArrayIns arr; + arr = new ArrayIns(maxSize); //create array + + for(int j=0; j