Class arraybub {
Private long [] A; // ref to array
Private int nelems; // Number of date items
Public arraybub (INT max) {// Constructor
A = new long [Max]; // create the Array
Nelems = 0; // No items yet
}
/**
* Insert
* @ Param Value
*/
Public void insert (long value) // put element into Array
{
A [nelems] = value; // insert it
Nelems ++; // increment size
}
/*
* Display data
*/
Public void display () // displays array Contents
{
For (Int J = 0; j <nelems; j ++)
// For each element,
System. Out. Print (A [J] + ""); // display it
System. Out. println ("");
}
/**
* Bubble Sorting
*/
Public void bubblesort (){
Int out, in;
For (out = nelems-1; out> 1; out --)
For (in = 0; in <out; in ++)
If (A [in]> A [in + 1])
Swap (in, in + 1 );
} // End bubblesort ()
//--------------------------------------------
Private void swap (INT one, int two ){
Long temp = A [one];
A [one] = a [two];
A [two] = temp;
}
//---------------------------------------------
} // End class arraybub
//////////////////////////////////////// ///////////
Public class bubblesort {
Public static void main (string ARGs []) {
Int maxsize = 100; // array size
Arraybub arr; // reference to array
Arr = new arraybub (maxsize); // create the Array
Arr. insert (77); // Insert 10 items
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 );
Arr. Display (); // display items
Arr. bubblesort (); // bubble sort them
Arr. Display ();
} // End main ()
} // End class bubblesortapp