procedure MergeSort(var Q: Queue); var QQ: array[boolean] of Queue; Q1, Q2 : Queue; V : TValue; i , all : boolean; begin i := false ; QQ[i] := Q; { QQ[false] := Входная очередь } Init (QQ[not i]); { QQ[true] := пусто } repeat if Empty(QQ[i]) then begin i:=noti; all := true 378end else all := false ; V := Top(QQ[i]); Pop(QQ[i]); Init (Q1); Init (Q2); while not Empty(QQ[i]) do begin if V > Top(QQ[i]) then break; Push(Q1, V); V := Top(QQ[i]) ; Pop(QQ[i]) end; Push(Q1, V); if not Empty(QQ[i]) then begin all := false ; V := Top(QQ[i]); Pop(QQ[i]); while not Empty(QQ[i]) do begin if V > Top(QQ[i]) then break; Push(Q2, V); V := Top(QQ[i]); Pop(QQ[i]) end; Push(Q2,V); Merge(Q1, Q2, QQ[not i]) end else begin while not Empty(Q1) do begin Push(QQ[not i], Top(Q1)); Pop(Q1) end end until all ; 379Q := QQ[not i] end;