Question: I developed the following sorting algorithm but there are some run time errors that I cant figure out. The program terminates when it comes to the part of filling the array. I'm still a beginner in ada so I couldn't figure out where the problem is...

```
With Ada.Text_IO;
With Ada.Integer_Text_IO;
Use Ada.Integer_Text_IO;
Use Ada.Text_IO;

Procedure sort is
   n,i,x : Integer;

   -- Max_Heapify Function...
   Procedure Max_Heapify ( i, n : integer) is 
      j, Temp : Integer;
   begin
      Temp:=Int_Acc(i);
      j:=2*i;

         if Temp>Int_Acc(j) then

         elsif Temp<=Int_Acc(j) then
            Int_Acc(j/2):=Int_Acc(j);
            j:=2*j;
         end if;
      end loop;
      Int_Acc(j/2):=Temp;
   end Max_Heapify;

begin
   Get(n);
      for i in MyArr'range loop
         Put_Line("Enter Element " & Integer'Image(i));
         Get(MyArr(i));
      end loop;
   end;
end sort;

```

Thanks in advance :)

Answer: 
Your Problem is that you are insisting on writing Ada code using c - Style programming paradigms.

**Firstly**: 

The declarations:

```
   Type Arr is array(1..20) of Integer;
   Type int_access is access Arr;
   MyArr : int_access;

```

Where you use `Int_Acc : in out int_access` as parameters to procedures are useless in Ada. You are trying to pass a pointer to an array in (which you are doing!), but you should just pass your `Type Arr` as `in out` - The Ada compiler knows to do this as a pointer!

**Secondly**:

I cannot see where you actually allocate any memory to `MyArr`. This is a possible source of your runtime error. (when you write to or index an array that does not exist, i would expect to have a problem!)

**Thirdly**:
You seem to be mixing fixed length arrays with variable length input. If N > 20, you will have a problem.

**Fourthly**:
[Insulting](https://stackoverflow.com/questions/22729858/my-heap-sorting-algorithm-runtime-errors#comment34641789_22729962) the language is not the best way of getting help from those who like it.
```
   if j<n **and then** Int_Acc(j+1)>Int_Acc(j) then
            j:=j+1;

```

I think you want just 'and' instead of 'and then,' although I haven't looked at Ada code in years.

Did that compile?