Ë
    Øªg  ã                   óR   — d Z d„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Ze	d	k(  r e«        y
y
)z·
This module provides a variety of list sorting algorithms, to
illustrate the many different algorithms (recipes) for solving a
problem, and how to analyze algorithms experimentally.
c                 óÆ   — d}t        t        | «      dz
  «      D ]D  }|}t        |dz   t        | «      «      D ]  }| |   | |   k  r|}|dz  }Œ | |   | |   c| |<   | |<   ŒF |S )zÔ
    Selection Sort: scan the list to find its smallest element, then
    swap it with the first element.  The remainder of the list is one
    element smaller; apply the same method to this list, and so on.
    é    é   ©ÚrangeÚlen)ÚaÚcountÚiÚminÚjs        úC/var/www/openai/venv/lib/python3.12/site-packages/nltk/misc/sort.pyÚ	selectionr      s   € ð €Eä”3q“6˜A‘:ÖˆØˆäq˜1‘uœc !›fÖ%ˆAØ‰ta˜‘fŠ}ØàQ‰J‰Eð	 &ð ˜‘t˜Q˜s™Vˆˆˆ#‰!’ð ð €Ló    c                 óÖ   — d}t        t        | «      dz
  «      D ]L  }t        t        | «      |z
  dz
  «      D ]-  }| |dz      | |   k  sŒ| |dz      | |   c| |<   | |dz   <   |dz  }Œ/ ŒN |S )aG  
    Bubble Sort: compare adjacent elements of the list left-to-right,
    and swap them if they are out of order.  After one pass through
    the list swapping adjacent items, the largest item will be in
    the rightmost position.  The remainder is one element smaller;
    apply the same method to this list, and so on.
    r   r   r   )r   r	   r
   r   s       r   Úbubbler   0   s   € ð €EÜ”3q“6˜A‘:ÖˆÜ”s˜1“v ‘z A‘~Ö&ˆAØQ‘‰x˜!˜A™$‹Ø!" 1 q¡5¡¨1¨Q©4!‘a˜˜A™‘hØ˜‘
‘ñ 'ð ð
 €Lr   c                 óV  — d}dx}}g }|t        | «      k  rn|t        |«      k  r`|dz  }| |   ||   k  r|j                  | |   «       |dz  }n|j                  ||   «       |dz  }|t        | «      k  r|t        |«      k  rŒ`|t        | «      k(  r|||d  z  }||fS || |d  z  }||fS ©Nr   r   )r   Úappend)ÚbÚcr	   r
   r   r   s         r   Ú_merge_listsr   F   sÊ   € Ø€EØ€I€AˆØ
€AØ
Œc!‹fŠ*˜œS ›VšØ‰
ˆØˆQ‰41Q‘4Š<ØH‰HQq‘TŒNØ‰F‰AàH‰HQq‘TŒNØ‰FˆAð Œc!‹fŠ*˜œS ›V›ð 	ŒC‹F‚{Ø	ˆQˆqˆrˆU‰
ˆð ˆeˆ8€Oð 	
ˆQˆqˆrˆU‰
ˆØˆeˆ8€Or   c                 óº   — d}t        | «      dkD  rJt        | «      dz  }| d| }| |d }t        |«      }t        |«      }t        ||«      \  }}|| dd ||z   |z   }|S )ze
    Merge Sort: split the list in half, and sort each half, then
    combine the sorted halves.
    r   r   é   N)r   Úmerger   )	r   r	   Úmidpointr   r   Úcount_bÚcount_cÚresultÚcount_as	            r   r   r   Y   sv   € ð
 €EÜ
ˆ1ƒv‚zÜq“6˜Q‘;ˆØˆiˆxˆLˆØˆhˆiˆLˆÜ˜“(ˆÜ˜“(ˆÜ& q¨!Ó,‰ˆØˆ‰!ˆØ˜'Ñ! GÑ+ˆØ€Lr   c                 ó  — | |   }|}|dz   }d}	 ||k  r|dz  }| |   |k\  rn||k  rŒ||kD  r|dz  }||k  s| |   |k  rn||kD  rŒ| |   | |   c| |<   | |<   |dz  }||k\  rnŒT| |   | |   c| |<   | |<   | |   | |   c| |<   | |<   ||fS )Nr   r   © )r   ÚlÚrÚpr
   r   r	   s          r   Ú
_partitionr%   p   sí   € Ø	ˆ!‰€AØ	€AØ	ˆA‰€AØ€EØ
Ø!ŠeØ‰FˆAØ‰tqŠyØð !‹eð !ŠeØ‰FˆAØ1Šu˜˜!™ š	Øð !‹eð q‘T˜1˜Q™4ˆ
ˆˆ!‰ˆa‰dØ‰
ˆØŠ6Øð ð 1‘q˜‘t€J€A€aDˆ!ˆA‰$Ø1‘q˜‘t€J€A€aDˆ!ˆA‰$Øˆeˆ8€Or   c                 ó€   — d}||k  r6t        | ||«      \  }}|t        | ||dz
  «      z  }|t        | |dz   |«      z  }|S r   )r%   Ú_quick)r   r"   r#   r	   Úss        r   r'   r'   ‡   sS   € Ø€EØˆ1‚uÜ˜a  AÓ&‰ˆˆ5Ø”˜˜1˜a !™eÓ$Ñ$ˆØ”˜˜1˜q™5 !Ó$Ñ$ˆØ€Lr   c                 ó4   — t        | dt        | «      dz
  «      S r   )r'   r   )r   s    r   Úquickr*      s   € Ü!Qœ˜A› ™
Ó#Ð#r   c            	      ó  — ddl m}  dD ]u  }t        t        |«      «      } | |«       t	        |«      } | |«       t        |«      } | |«       t        |«      } | |«       t        |«      }t        d|||||fz  «       Œw y )Nr   )Úshuffle)é
   é   é2   éd   éÈ   iô  iè  z=size=%5d:  selection=%8d,  bubble=%8d,  merge=%6d,  quick=%6d)	Úrandomr,   Úlistr   r   r   r   r*   Úprint)r,   Úsizer   Úcount_selectionÚcount_bubbleÚcount_mergeÚcount_quicks          r   Údemor:   ™   s~   € Ýã1ˆÜ”t“Óˆñ 	Œ
Ü# A›,ˆÙŒ
Ü˜a“yˆÙŒ
Ü˜A“hˆÙŒ
Ü˜A“hˆäØOØ_ l°KÀÐMñNõ	
ñ 2r   Ú__main__N)
Ú__doc__r   r   r   r   r%   r'   r*   r:   Ú__name__r!   r   r   Ú<module>r>      sF   ðñòò6ò,ò&ò.ò.ò$ò
ð, ˆzÒÙ…Fð r   