• English only

# Lab for Automated Reasoning and Analysis LARA

```program QuickSort {
println(new QS().Start(10));
}

// This class contains the array of integers and
// methods to initialize, print and sort the array
// using Quicksort
class QS {
var number : Int[];
var size : Int;

// Invoke the Initialization, Sort and Printing
// Methods
def Start(sz : Int) : Int = {
do(this.Init(sz));
do(this.Print());
println(9999);
do(this.Sort(0,size - 1));
do(this.Print());
return 9999;
}

// Sort array of integers using Quicksort method
def Sort(left : Int, right : Int) : Int = {
var v : Int;
var i : Int;
var j : Int;
var nt : Int;
var t : Int;
var cont01 : Bool;
var cont02 : Bool;
var aux03 : Int;

t = 0 ;
if (left < right){
v = number[right] ;
i = left - 1 ;
j = right ;
cont01 = true ;
while (cont01){
cont02 = true ;
while (cont02){
i = i + 1 ;
aux03 = number[i] ;
if (!(aux03<v)) cont02 = false ;
else cont02 = true ;
}
cont02 = true ;
while (cont02){
j = j - 1 ;
aux03 = number[j] ;
if (!(v < aux03)) cont02 = false ;
else cont02 = true ;
}

t = number[i] ;
number[i] = number[j] ;
number[j] = t ;
//aux03 = i + 1 ;
if ( j < (i+1)) cont01 = false ;
else cont01 = true ;
}
number[j] = number[i] ;
number[i] = number[right] ;
number[right] = t ;
nt = this.Sort(left,i-1);
nt = this.Sort(i+1,right);
}
else nt = 0 ;
return 0 ;
}

def Print() : Int = {
var j : Int;

j = 0 ;
while (j < (size)) {
println(number[j]);
j = j + 1 ;
}
return 0 ;
}

// Initialize array of integers
def Init(sz : Int) : Int = {
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 ;
}
}```

cc16/toolprog-quicksort.tool.txt · Last modified: 2016/09/20 20:00 by manos

© EPFL 2018 - Legal notice