الفرق بين المراجعتين ل"Kotlin/collections/sortDescending"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: الدالة <code>sortDescending()‎</code> في لغة Kotlin}}</noinclude> تقوم الدالة<code>sortDescending()‎</code> بترت...')
 
سطر 1: سطر 1:
 
<noinclude>{{DISPLAYTITLE: الدالة <code>sortDescending()‎</code> في لغة Kotlin}}</noinclude>
 
<noinclude>{{DISPLAYTITLE: الدالة <code>sortDescending()‎</code> في لغة Kotlin}}</noinclude>
تقوم الدالة<code>sortDescending()‎</code> بترتيب  [[Kotlin/Array|المصفوفة]] أو [[kotlin/MutableList|اللائحة المتغيرة]] (<code>MutableList</code>) التي استُدعيت عبرها.  
+
تقوم الدالة<code>sortDescending()‎</code> بترتيب  [[Kotlin/Array|المصفوفة]] أو [[kotlin/MutableList|اللائحة المتغيرة]] (<code>MutableList</code>) التي استُدعيت عبرها تنازليًا.  
  
 
==البنية العامة==
 
==البنية العامة==
في حال استدعاء الدالة  <code>sortDescending()‎</code> عبر  [[Kotlin/Array|مصفوفة]] فستقوم بترتيبها: <nowiki/><nowiki/><syntaxhighlight lang="kotlin">
+
يمكن استدعاء الدالة  <code>sortDescending()‎</code> عبر  [[Kotlin/Array|المصفوفات]] فستقوم بترتيبها: <nowiki/><nowiki/><syntaxhighlight lang="kotlin">
fun IntArray.sort()
+
fun <T : Comparable<T>> Array<out T>.sortDescending()  
fun LongArray.sort()
+
fun ByteArray.sortDescending()  
fun ByteArray.sort()
+
fun ShortArray.sortDescending()  
fun ShortArray.sort()
+
fun IntArray.sortDescending()  
fun DoubleArray.sort()
+
fun LongArray.sortDescending()  
fun FloatArray.sort()
+
fun FloatArray.sortDescending()  
fun CharArray.sort()
+
fun DoubleArray.sortDescending()  
inline fun <T : Comparable<T>> Array<out T>.sort() (source)
+
fun CharArray.sortDescending()  
 
+
</syntaxhighlight>يمكن<nowiki/><nowiki/> استدعاء الدالة  <code>sortDescending()‎</code> عبر  كائن من النوع <code>[[kotlin/MutableList|MutableList]]</code>:<nowiki/><nowiki/><syntaxhighlight lang="kotlin">
</syntaxhighlight>في حال استدعاء الدالة  <code>sortDescending()‎</code> عبر  [[Kotlin/Array|مصفوفة]] مع تمرير معاملين عددين فستقوم بترتيب المجال المحدد بذلك المعاملين داخل [[Kotlin/Array|المصفوفة]]: <nowiki/><nowiki/><syntaxhighlight lang="kotlin">
+
fun <T : Comparable<T>> MutableList<T>.sortDescending()  
fun <T> Array<out T>.sort(
 
    fromIndex: Int = 0,
 
    toIndex: Int = size)
 
fun ByteArray.sort(fromIndex: Int = 0, toIndex: Int = size)  
 
fun ShortArray.sort(fromIndex: Int = 0, toIndex: Int = size)
 
fun IntArray.sort(fromIndex: Int = 0, toIndex: Int = size)  
 
fun LongArray.sort(fromIndex: Int = 0, toIndex: Int = size)
 
fun FloatArray.sort(fromIndex: Int = 0, toIndex: Int = size)  
 
fun DoubleArray.sort(fromIndex: Int = 0, toIndex: Int = size)
 
fun CharArray.sort(fromIndex: Int = 0, toIndex: Int = size)  
 
 
 
</syntaxhighlight>'''بيئة التشغيل: JVM'''
 
 
 
في حال استدعاء الدالة  <code>sortDescending()‎</code> عبر  كائن من النوع <code>[[kotlin/MutableList|MutableList]]</code> فستقوم بترتيبه:<syntaxhighlight lang="kotlin">
 
fun <T : Comparable<T>> MutableList<T>.sort()
 
 
 
</syntaxhighlight>في حال استدعاء الدالة  <code>sortDescending()‎</code> عبر  [[Kotlin/Array|مصفوفة]] مع تمرير مًقارن <code>comparison</code> كمعامل فستقوم بترتيب تلك [[Kotlin/Array|المصفوفة]] بحسب الترتيب الذي يحدده المقارن <code>comparison</code>: <syntaxhighlight lang="kotlin">
 
inline fun <T> Array<out T>.sort(
 
    noinline comparison: (a: T, b: T) -> Int)
 
inline fun ByteArray.sort(
 
    noinline comparison: (a: Byte, b: Byte) -> Int)
 
inline fun ShortArray.sort(
 
    noinline comparison: (a: Short, b: Short) -> Int)
 
inline fun IntArray.sort(
 
    noinline comparison: (a: Int, b: Int) -> Int)
 
inline fun LongArray.sort(
 
    noinline comparison: (a: Long, b: Long) -> Int)
 
inline fun FloatArray.sort(
 
    noinline comparison: (a: Float, b: Float) -> Int)
 
inline fun DoubleArray.sort(
 
    noinline comparison: (a: Double, b: Double) -> Int)
 
inline fun CharArray.sort(
 
    noinline comparison: (a: Char, b: Char) -> Int)
 
 
 
</syntaxhighlight>يُلاحَظ وجود الكلمة المفتاحية <code>inline</code> للدلالة على أن هذه الدالة مباشرة، وللمزيد من التفاصيل راجع <nowiki/>[[Kotlin/inline functions|توثيق الدوال المباشرة (inline functions)]].
 
  
 +
</syntaxhighlight>
 
==أمثلة==
 
==أمثلة==
 
===استخدام الدالة <code>()sortDescending</code> مع المصفوفات===
 
===استخدام الدالة <code>()sortDescending</code> مع المصفوفات===
تعرف الشيفرة الآتية  <nowiki/>[[Kotlin/Array|مصفوفة]]<nowiki/>باسم <code>array</code> مكونة من ستة عناصر باستخدام الدالة <code>()arrayOf‎</code>، ثم تستخدم الدالة<code>()sortDescending</code>  على <code>array</code> لترتيبه، ثم تطبع الناتج:<syntaxhighlight lang="kotlin">
+
تعرف الشيفرة الآتية  <nowiki/>[[Kotlin/Array|مصفوفة]]<nowiki/>باسم <code>array</code> مكونة من ستة عناصر باستخدام الدالة <code>()arrayOf‎</code>، ثم تستخدم الدالة<code>()sortDescending</code>  على <code>array</code> لترتيبه تنازليًا، ثم تطبع الناتج:<syntaxhighlight lang="kotlin">
 
import java.util.Arrays
 
import java.util.Arrays
  
 
fun main(args: Array<String>) {
 
fun main(args: Array<String>) {
val array = arrayOf(1, 9, 3, 7, 5, 6)
+
val array = arrayOf(1, 9, -3, 7, 5, 6)
 
+
array.sortDescending()  
array.sort()
 
 
      
 
      
print (Arrays.toString(array)) // [1, 3, 5, 6, 7, 9]
+
print (Arrays.toString(array)) // [9, 7, 6, 5, 1, -3]
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
==أنظر أيضًا==
 
==أنظر أيضًا==
 
*<code>[[Kotlin/collections/sortBy|sortBy()]]</code>‎ : تقوم بترتيب  [[Kotlin/Array|المصفوفة]] أو [[Kotlin/MutableList|اللائحة المتغيرة]] (<code>MutableList</code>) التي استُدعيت عبرها وفقًا للقيم التي تعيدها الدالة المُمرّرة . 
 
*<code>[[Kotlin/collections/sortBy|sortBy()]]</code>‎ : تقوم بترتيب  [[Kotlin/Array|المصفوفة]] أو [[Kotlin/MutableList|اللائحة المتغيرة]] (<code>MutableList</code>) التي استُدعيت عبرها وفقًا للقيم التي تعيدها الدالة المُمرّرة . 
 +
 +
* <code>[[Kotlin/collections/sort|sort()]]</code>‎ : تقوم بترتيب <nowiki/>[[Kotlin/Array|المصفوفة]] أو اللائحة المتغيرة (<code>MutableList</code>) التي استُدعيت عبرها. 
 +
*
 +
 
==مصادر==
 
==مصادر==
*[https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/sort.html الدالة  sortDescending()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
+
*[https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/sort-descending.html الدالة  sortDescending()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin Functions]]
 
[[تصنيف:Kotlin Functions]]

مراجعة 18:15، 6 يونيو 2018

تقوم الدالةsortDescending()‎ بترتيب المصفوفة أو اللائحة المتغيرة (MutableList) التي استُدعيت عبرها تنازليًا.

البنية العامة

يمكن استدعاء الدالة  sortDescending()‎ عبر المصفوفات فستقوم بترتيبها:

fun <T : Comparable<T>> Array<out T>.sortDescending() 
fun ByteArray.sortDescending() 
fun ShortArray.sortDescending() 
fun IntArray.sortDescending() 
fun LongArray.sortDescending() 
fun FloatArray.sortDescending() 
fun DoubleArray.sortDescending() 
fun CharArray.sortDescending()

يمكن استدعاء الدالة  sortDescending()‎ عبر كائن من النوع MutableList:

fun <T : Comparable<T>> MutableList<T>.sortDescending()

أمثلة

استخدام الدالة ()sortDescending مع المصفوفات

تعرف الشيفرة الآتية  مصفوفةباسم array مكونة من ستة عناصر باستخدام الدالة ()arrayOf‎، ثم تستخدم الدالة()sortDescending  على array لترتيبه تنازليًا، ثم تطبع الناتج:

import java.util.Arrays

fun main(args: Array<String>) {
val array = arrayOf(1, 9, -3, 7, 5, 6)
array.sortDescending()    
    
print (Arrays.toString(array)) // [9, 7, 6, 5, 1, -3]
}

أنظر أيضًا

  • sort()‎ : تقوم بترتيب المصفوفة أو اللائحة المتغيرة (MutableList) التي استُدعيت عبرها. 

مصادر