Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

How to sort the part of an array in Pascal

1 Answer

0 votes
program PartialSort;

var
  arr: array of Integer;
  i: Integer;

// Procedure to sort a portion of the array from startIndex to endIndex (inclusive)
procedure SortSubArray(var a: array of Integer; startIndex, endIndex: Integer);
var
  i, j, temp: Integer;
begin
  for i := startIndex to endIndex do
    for j := i + 1 to endIndex do
      if a[j] < a[i] then
      begin
        temp := a[i];
        a[i] := a[j];
        a[j] := temp;
      end;
end;

begin
  // Set the length of the dynamic array
  SetLength(arr, 9);

  // Assign values manually
  arr[0] := 15;
  arr[1] := 6;
  arr[2] := 19;
  arr[3] := 8;
  arr[4] := 3;
  arr[5] := 7;
  arr[6] := 9;
  arr[7] := 1;
  arr[8] := 4;

  // Sort elements from index 2 to 6 (inclusive)
  SortSubArray(arr, 2, 6);

  // Print the updated array
  for i := 0 to High(arr) do
    Write(arr[i], ' ');
  WriteLn;
end.

 



answered Aug 12, 2025 by avibootz
edited Aug 12, 2025 by avibootz
...