Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
82e6a8f8
Kaydet (Commit)
82e6a8f8
authored
Nis 28, 1998
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Quicksort retuned by Tim Peters.
üst
bee64533
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
33 deletions
+26
-33
listobject.c
Objects/listobject.c
+26
-33
No files found.
Objects/listobject.c
Dosyayı görüntüle @
82e6a8f8
...
@@ -634,7 +634,7 @@ static int
...
@@ -634,7 +634,7 @@ static int
insertionsort
(
array
,
size
,
compare
)
insertionsort
(
array
,
size
,
compare
)
PyObject
**
array
;
/* Start of array to sort */
PyObject
**
array
;
/* Start of array to sort */
int
size
;
/* Number of elements to sort */
int
size
;
/* Number of elements to sort */
PyObject
*
compare
;
/* Comparison function object, or NULL
for
default */
PyObject
*
compare
;
/* Comparison function object, or NULL
=>
default */
{
{
register
PyObject
**
a
=
array
;
register
PyObject
**
a
=
array
;
register
PyObject
**
end
=
array
+
size
;
register
PyObject
**
end
=
array
+
size
;
...
@@ -645,6 +645,8 @@ insertionsort(array, size, compare)
...
@@ -645,6 +645,8 @@ insertionsort(array, size, compare)
register
PyObject
**
q
=
p
;
register
PyObject
**
q
=
p
;
while
(
--
q
>=
a
)
{
while
(
--
q
>=
a
)
{
register
int
k
=
docompare
(
*
q
,
key
,
compare
);
register
int
k
=
docompare
(
*
q
,
key
,
compare
);
/* if (p-q >= MINSIZE)
fprintf(stderr, "OUCH! %d\n", p-q); */
if
(
k
==
CMPERROR
)
if
(
k
==
CMPERROR
)
return
-
1
;
return
-
1
;
if
(
k
<=
0
)
if
(
k
<=
0
)
...
@@ -703,7 +705,7 @@ quicksort(array, size, compare)
...
@@ -703,7 +705,7 @@ quicksort(array, size, compare)
n
=
hi
-
lo
;
n
=
hi
-
lo
;
if
(
n
<
MINSIZE
)
{
if
(
n
<
MINSIZE
)
{
/*
/*
* skip it. The insertion sort at the end will
* skip it. The insertion sort at the end will
* catch these
* catch these
*/
*/
continue
;
continue
;
...
@@ -733,11 +735,14 @@ quicksort(array, size, compare)
...
@@ -733,11 +735,14 @@ quicksort(array, size, compare)
{
tmp
=
*
l
;
*
l
=
*
lo
;
*
lo
=
tmp
;
}
{
tmp
=
*
l
;
*
l
=
*
lo
;
*
lo
=
tmp
;
}
pivot
=
*
l
;
pivot
=
*
l
;
/* Move pivot off to the side (swap with lo+1) */
*
l
=
*
(
lo
+
1
);
*
(
lo
+
1
)
=
pivot
;
/* Partition the array */
/* Partition the array */
l
=
lo
+
1
;
l
=
lo
+
2
;
r
=
hi
-
2
;
r
=
hi
-
2
;
for
(;;)
{
do
{
/* Move left index to element > pivot */
/* Move left index to element >
=
pivot */
while
(
l
<
hi
)
{
while
(
l
<
hi
)
{
k
=
docompare
(
*
l
,
pivot
,
compare
);
k
=
docompare
(
*
l
,
pivot
,
compare
);
if
(
k
==
CMPERROR
)
if
(
k
==
CMPERROR
)
...
@@ -746,8 +751,8 @@ quicksort(array, size, compare)
...
@@ -746,8 +751,8 @@ quicksort(array, size, compare)
break
;
break
;
l
++
;
l
++
;
}
}
/* Move right index to element < pivot */
/* Move right index to element <
=
pivot */
while
(
r
>
=
lo
)
{
while
(
r
>
lo
)
{
k
=
docompare
(
pivot
,
*
r
,
compare
);
k
=
docompare
(
pivot
,
*
r
,
compare
);
if
(
k
==
CMPERROR
)
if
(
k
==
CMPERROR
)
return
-
1
;
return
-
1
;
...
@@ -756,21 +761,17 @@ quicksort(array, size, compare)
...
@@ -756,21 +761,17 @@ quicksort(array, size, compare)
r
--
;
r
--
;
}
}
/* If they
met
, we're through */
/* If they
crossed
, we're through */
if
(
l
<
r
)
{
if
(
l
<
=
r
)
{
/* Swap elements and continue */
/* Swap elements and continue */
tmp
=
*
l
;
*
l
=
*
r
;
*
r
=
tmp
;
tmp
=
*
l
;
*
l
=
*
r
;
*
r
=
tmp
;
l
++
;
r
--
;
l
++
;
r
--
;
}
}
else
if
(
l
==
r
)
{
l
++
;
r
--
;
break
;
}
if
(
l
>
r
)
}
while
(
l
<=
r
);
break
;
}
/* Swap pivot back into place; *r <= pivot */
*
(
lo
+
1
)
=
*
r
;
*
r
=
pivot
;
/* We have now reached the following conditions:
/* We have now reached the following conditions:
lo <= r < l <= hi
lo <= r < l <= hi
...
@@ -785,27 +786,19 @@ quicksort(array, size, compare)
...
@@ -785,27 +786,19 @@ quicksort(array, size, compare)
n2
=
hi
-
l
;
n2
=
hi
-
l
;
if
(
n
>
n2
)
{
if
(
n
>
n2
)
{
/* First one is bigger */
/* First one is bigger */
if
(
n
>
MINSIZE
)
{
lostack
[
top
]
=
lo
;
lostack
[
top
]
=
lo
;
histack
[
top
++
]
=
r
;
histack
[
top
++
]
=
r
;
lostack
[
top
]
=
l
;
if
(
n2
>
MINSIZE
)
{
histack
[
top
++
]
=
hi
;
lostack
[
top
]
=
l
;
histack
[
top
++
]
=
hi
;
}
}
}
else
{
}
else
{
/* Second one is bigger */
/* Second one is bigger */
if
(
n2
>
MINSIZE
)
{
lostack
[
top
]
=
l
;
lostack
[
top
]
=
l
;
histack
[
top
++
]
=
hi
;
histack
[
top
++
]
=
hi
;
lostack
[
top
]
=
lo
;
if
(
n
>
MINSIZE
)
{
histack
[
top
++
]
=
r
;
lostack
[
top
]
=
lo
;
histack
[
top
++
]
=
r
;
}
}
}
}
/* Should assert top <
STACKSIZE-1
*/
/* Should assert top <
= STACKSIZE
*/
}
}
/*
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment