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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,227 questions

56,129 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
...