summaryrefslogtreecommitdiff
path: root/output/BubbleSort.java
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-26 23:33:15 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-26 23:33:15 -0600
commitff12bb1dd11c509fc7ac7529085df2d2407b0ece (patch)
tree81becf519d2027b7729fee73cde49137f22ebbef /output/BubbleSort.java
parent5db69446e6e898129c28bea19fbb8bb111c5101c (diff)
Add my test library
Diffstat (limited to 'output/BubbleSort.java')
-rw-r--r--output/BubbleSort.java93
1 files changed, 93 insertions, 0 deletions
diff --git a/output/BubbleSort.java b/output/BubbleSort.java
new file mode 100644
index 0000000..e5645a9
--- /dev/null
+++ b/output/BubbleSort.java
@@ -0,0 +1,93 @@
+class BubbleSort{
+ public static void main(String[] a){
+ System.out.println(new BBS().Start(10));
+ }
+}
+
+
+// This class contains the array of integers and
+// methods to initialize, print and sort the array
+// using Bublesort
+class BBS{
+
+ int[] number ;
+ int size ;
+
+ // Invoke the Initialization, Sort and Printing
+ // Methods
+ public int Start(int sz){
+ int aux01 ;
+ aux01 = this.Init(sz);
+ aux01 = this.Print();
+ System.out.println(99999);
+ aux01 = this.Sort();
+ aux01 = this.Print();
+ return 0 ;
+ }
+
+
+ // Sort array of integers using Bublesort method
+ public int Sort(){
+ int nt ;
+ int i ;
+ int aux02 ;
+ int aux04 ;
+ int aux05 ;
+ int aux06 ;
+ int aux07 ;
+ int j ;
+ int t ;
+ i = size - 1 ;
+ aux02 = 0 - 1 ;
+ while (aux02 < i) {
+ j = 1 ;
+ //aux03 = i+1 ;
+ while (j < (i+1)){
+ aux07 = j - 1 ;
+ aux04 = number[aux07] ;
+ aux05 = number[j] ;
+ if (aux05 < aux04) {
+ aux06 = j - 1 ;
+ t = number[aux06] ;
+ number[aux06] = number[j] ;
+ number[j] = t;
+ }
+ else nt = 0 ;
+ j = j + 1 ;
+ }
+ i = i - 1 ;
+ }
+ return 0 ;
+ }
+
+ // Printing method
+ public int Print(){
+ int j ;
+ j = 0 ;
+ while (j < (size)) {
+ System.out.println(number[j]);
+ j = j + 1 ;
+ }
+ return 0 ;
+ }
+
+ // Initialize array of integers
+ public int Init(int sz){
+ size = sz ;
+ number = new int[sz] ;
+
+ number[0] = 20 ;
+ number[1] = 7 ;
+ number[2] = 12 ;
+ number[3] = 18 ;
+ number[4] = 2 ;
+ number[5] = 11 ;
+ number[6] = 6 ;
+ number[7] = 9 ;
+ number[8] = 19 ;
+ number[9] = 5 ;
+
+ return 0 ;
+ }
+
+}