SlideShare uma empresa Scribd logo
1 de 1
Baixar para ler offline
Write a Kotlin program with a checkSorting() generic function. The checkSorting()
function accepts two arguments: an input list and a function that determines the
comparison condition. The function should be able to accept any list belonging to the
Number supertype. The user should be able to specify through the function argument the
condition using which a list will be considered sorted. For example, a list (1,2,3,4,5) is
considered sorted if we are using a comparison condition where each (n-1)th element
should be less than each nth element, otherwise it is considered unsorted. The function
checkSorting() returns True of a list is sorted, otherwise it returns false.
Please note that checkSorting should be written as a pure function, therefore, it should be
recursive and use an internal helper function. Test your program by at least two calls to this
function from main using any two distinct number subtypes of your choice.
Hint: To compare elements of an array, you will need to write two extension functions. An
extension function allows you to add helpful behavior for a type or instance. To declare an
extension function, prefix its name with the type of the data to which you would like to add
the behavior. The following is an example of an extension function show() that we would like
to apply to an Int to show the Ints value.
fun Int.show(): String = "The value of this Int is $this"
1.show()
res1: kotlin.String = The value of this Int is 1
The two extension function you will require are tail() and head(). tail() uses the drop method
for lists which returns a list containing all elements except the first n elements. head() uses
the first method for lists which returns the first element on the list. For more information,
please refer to the following links:
Extension functions: http://developer.android.com
drop(): https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/drop.html
first(): https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/first.html

Mais conteúdo relacionado

Semelhante a Write a Kotlin program with a checkSorting generic functio.pdf

Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsMegha V
 
C++ Please make sure that your answer is fully submitted .pdf
C++ Please make sure that your answer is fully submitted .pdfC++ Please make sure that your answer is fully submitted .pdf
C++ Please make sure that your answer is fully submitted .pdfaashkaahm
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)Arpit Meena
 
All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... FunctionsMichal Bigos
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Twoamiable_indian
 
PE1 Module 3.ppt
PE1 Module 3.pptPE1 Module 3.ppt
PE1 Module 3.pptbalewayalew
 
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfComplete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfshahidqamar17
 
Vizwik Coding Manual
Vizwik Coding ManualVizwik Coding Manual
Vizwik Coding ManualVizwik
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxjane3dyson92312
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxfestockton
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptxRhishav Poudyal
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfLinked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfadityacomputers001
 

Semelhante a Write a Kotlin program with a checkSorting generic functio.pdf (20)

Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
 
C++ Please make sure that your answer is fully submitted .pdf
C++ Please make sure that your answer is fully submitted .pdfC++ Please make sure that your answer is fully submitted .pdf
C++ Please make sure that your answer is fully submitted .pdf
 
functions- best.pdf
functions- best.pdffunctions- best.pdf
functions- best.pdf
 
Functions
FunctionsFunctions
Functions
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
 
All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... Functions
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
PE1 Module 3.ppt
PE1 Module 3.pptPE1 Module 3.ppt
PE1 Module 3.ppt
 
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfComplete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
 
Parametricity
ParametricityParametricity
Parametricity
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Vizwik Coding Manual
Vizwik Coding ManualVizwik Coding Manual
Vizwik Coding Manual
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfLinked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdf
 

Mais de agpcorp

Wrte a function gotPC that accepts three arguments UD and .pdf
Wrte a function gotPC that accepts three arguments UD and .pdfWrte a function gotPC that accepts three arguments UD and .pdf
Wrte a function gotPC that accepts three arguments UD and .pdfagpcorp
 
WRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdf
WRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdfWRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdf
WRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdfagpcorp
 
Write TWO recursive methods One to find the maximum in an a.pdf
Write TWO recursive methods One to find the maximum in an a.pdfWrite TWO recursive methods One to find the maximum in an a.pdf
Write TWO recursive methods One to find the maximum in an a.pdfagpcorp
 
Write the R code to generate the following output by using c.pdf
Write the R code to generate the following output by using c.pdfWrite the R code to generate the following output by using c.pdf
Write the R code to generate the following output by using c.pdfagpcorp
 
Write the name of the structure the phrase describes 1 Blo.pdf
Write the name of the structure the phrase describes 1 Blo.pdfWrite the name of the structure the phrase describes 1 Blo.pdf
Write the name of the structure the phrase describes 1 Blo.pdfagpcorp
 
Write TensorFlow program to create a Binary image classifi.pdf
Write TensorFlow program  to  create a Binary image classifi.pdfWrite TensorFlow program  to  create a Binary image classifi.pdf
Write TensorFlow program to create a Binary image classifi.pdfagpcorp
 
Write python code that calculates the minimum maximum mean.pdf
Write python code that calculates the minimum maximum mean.pdfWrite python code that calculates the minimum maximum mean.pdf
Write python code that calculates the minimum maximum mean.pdfagpcorp
 
Write the Asymptotic Complexity for each line of code Then .pdf
Write the Asymptotic Complexity for each line of code Then .pdfWrite the Asymptotic Complexity for each line of code Then .pdf
Write the Asymptotic Complexity for each line of code Then .pdfagpcorp
 
Write Short answers specific and avoid extra off topic det.pdf
Write Short answers specific and avoid extra off topic det.pdfWrite Short answers specific and avoid extra off topic det.pdf
Write Short answers specific and avoid extra off topic det.pdfagpcorp
 
write report that will Evaluate your organizations IT infras.pdf
write report that will Evaluate your organizations IT infras.pdfwrite report that will Evaluate your organizations IT infras.pdf
write report that will Evaluate your organizations IT infras.pdfagpcorp
 
Write the assembly program Can use put_qword_safe to pr.pdf
Write the assembly program Can use put_qword_safe to pr.pdfWrite the assembly program Can use put_qword_safe to pr.pdf
Write the assembly program Can use put_qword_safe to pr.pdfagpcorp
 
Write program in JavaC to sort the given array using merge .pdf
Write program in JavaC to sort the given array using merge .pdfWrite program in JavaC to sort the given array using merge .pdf
Write program in JavaC to sort the given array using merge .pdfagpcorp
 
Write the Asymptotic Complexity for each line of code and th.pdf
Write the Asymptotic Complexity for each line of code and th.pdfWrite the Asymptotic Complexity for each line of code and th.pdf
Write the Asymptotic Complexity for each line of code and th.pdfagpcorp
 
Write the below pseudo code segment using a multipleselecti.pdf
Write the below pseudo code segment using a multipleselecti.pdfWrite the below pseudo code segment using a multipleselecti.pdf
Write the below pseudo code segment using a multipleselecti.pdfagpcorp
 
Write node express application that displays the rectangle f.pdf
Write node express application that displays the rectangle f.pdfWrite node express application that displays the rectangle f.pdf
Write node express application that displays the rectangle f.pdfagpcorp
 
write information about the plant propertieseffects of coca.pdf
write information about the plant propertieseffects of coca.pdfwrite information about the plant propertieseffects of coca.pdf
write information about the plant propertieseffects of coca.pdfagpcorp
 
Write in SML A proper divisor of a natural number is the div.pdf
Write in SML A proper divisor of a natural number is the div.pdfWrite in SML A proper divisor of a natural number is the div.pdf
Write in SML A proper divisor of a natural number is the div.pdfagpcorp
 
Write a main method that will request the user to enter Stri.pdf
Write a main method that will request the user to enter Stri.pdfWrite a main method that will request the user to enter Stri.pdf
Write a main method that will request the user to enter Stri.pdfagpcorp
 
Write combining forms for each of the following terms 1 an.pdf
Write combining forms for each of the following terms 1 an.pdfWrite combining forms for each of the following terms 1 an.pdf
Write combining forms for each of the following terms 1 an.pdfagpcorp
 
Write code for problem 2 please Create a linked list by ent.pdf
Write code for problem 2 please  Create a linked list by ent.pdfWrite code for problem 2 please  Create a linked list by ent.pdf
Write code for problem 2 please Create a linked list by ent.pdfagpcorp
 

Mais de agpcorp (20)

Wrte a function gotPC that accepts three arguments UD and .pdf
Wrte a function gotPC that accepts three arguments UD and .pdfWrte a function gotPC that accepts three arguments UD and .pdf
Wrte a function gotPC that accepts three arguments UD and .pdf
 
WRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdf
WRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdfWRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdf
WRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdf
 
Write TWO recursive methods One to find the maximum in an a.pdf
Write TWO recursive methods One to find the maximum in an a.pdfWrite TWO recursive methods One to find the maximum in an a.pdf
Write TWO recursive methods One to find the maximum in an a.pdf
 
Write the R code to generate the following output by using c.pdf
Write the R code to generate the following output by using c.pdfWrite the R code to generate the following output by using c.pdf
Write the R code to generate the following output by using c.pdf
 
Write the name of the structure the phrase describes 1 Blo.pdf
Write the name of the structure the phrase describes 1 Blo.pdfWrite the name of the structure the phrase describes 1 Blo.pdf
Write the name of the structure the phrase describes 1 Blo.pdf
 
Write TensorFlow program to create a Binary image classifi.pdf
Write TensorFlow program  to  create a Binary image classifi.pdfWrite TensorFlow program  to  create a Binary image classifi.pdf
Write TensorFlow program to create a Binary image classifi.pdf
 
Write python code that calculates the minimum maximum mean.pdf
Write python code that calculates the minimum maximum mean.pdfWrite python code that calculates the minimum maximum mean.pdf
Write python code that calculates the minimum maximum mean.pdf
 
Write the Asymptotic Complexity for each line of code Then .pdf
Write the Asymptotic Complexity for each line of code Then .pdfWrite the Asymptotic Complexity for each line of code Then .pdf
Write the Asymptotic Complexity for each line of code Then .pdf
 
Write Short answers specific and avoid extra off topic det.pdf
Write Short answers specific and avoid extra off topic det.pdfWrite Short answers specific and avoid extra off topic det.pdf
Write Short answers specific and avoid extra off topic det.pdf
 
write report that will Evaluate your organizations IT infras.pdf
write report that will Evaluate your organizations IT infras.pdfwrite report that will Evaluate your organizations IT infras.pdf
write report that will Evaluate your organizations IT infras.pdf
 
Write the assembly program Can use put_qword_safe to pr.pdf
Write the assembly program Can use put_qword_safe to pr.pdfWrite the assembly program Can use put_qword_safe to pr.pdf
Write the assembly program Can use put_qword_safe to pr.pdf
 
Write program in JavaC to sort the given array using merge .pdf
Write program in JavaC to sort the given array using merge .pdfWrite program in JavaC to sort the given array using merge .pdf
Write program in JavaC to sort the given array using merge .pdf
 
Write the Asymptotic Complexity for each line of code and th.pdf
Write the Asymptotic Complexity for each line of code and th.pdfWrite the Asymptotic Complexity for each line of code and th.pdf
Write the Asymptotic Complexity for each line of code and th.pdf
 
Write the below pseudo code segment using a multipleselecti.pdf
Write the below pseudo code segment using a multipleselecti.pdfWrite the below pseudo code segment using a multipleselecti.pdf
Write the below pseudo code segment using a multipleselecti.pdf
 
Write node express application that displays the rectangle f.pdf
Write node express application that displays the rectangle f.pdfWrite node express application that displays the rectangle f.pdf
Write node express application that displays the rectangle f.pdf
 
write information about the plant propertieseffects of coca.pdf
write information about the plant propertieseffects of coca.pdfwrite information about the plant propertieseffects of coca.pdf
write information about the plant propertieseffects of coca.pdf
 
Write in SML A proper divisor of a natural number is the div.pdf
Write in SML A proper divisor of a natural number is the div.pdfWrite in SML A proper divisor of a natural number is the div.pdf
Write in SML A proper divisor of a natural number is the div.pdf
 
Write a main method that will request the user to enter Stri.pdf
Write a main method that will request the user to enter Stri.pdfWrite a main method that will request the user to enter Stri.pdf
Write a main method that will request the user to enter Stri.pdf
 
Write combining forms for each of the following terms 1 an.pdf
Write combining forms for each of the following terms 1 an.pdfWrite combining forms for each of the following terms 1 an.pdf
Write combining forms for each of the following terms 1 an.pdf
 
Write code for problem 2 please Create a linked list by ent.pdf
Write code for problem 2 please  Create a linked list by ent.pdfWrite code for problem 2 please  Create a linked list by ent.pdf
Write code for problem 2 please Create a linked list by ent.pdf
 

Último

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 

Último (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

Write a Kotlin program with a checkSorting generic functio.pdf

  • 1. Write a Kotlin program with a checkSorting() generic function. The checkSorting() function accepts two arguments: an input list and a function that determines the comparison condition. The function should be able to accept any list belonging to the Number supertype. The user should be able to specify through the function argument the condition using which a list will be considered sorted. For example, a list (1,2,3,4,5) is considered sorted if we are using a comparison condition where each (n-1)th element should be less than each nth element, otherwise it is considered unsorted. The function checkSorting() returns True of a list is sorted, otherwise it returns false. Please note that checkSorting should be written as a pure function, therefore, it should be recursive and use an internal helper function. Test your program by at least two calls to this function from main using any two distinct number subtypes of your choice. Hint: To compare elements of an array, you will need to write two extension functions. An extension function allows you to add helpful behavior for a type or instance. To declare an extension function, prefix its name with the type of the data to which you would like to add the behavior. The following is an example of an extension function show() that we would like to apply to an Int to show the Ints value. fun Int.show(): String = "The value of this Int is $this" 1.show() res1: kotlin.String = The value of this Int is 1 The two extension function you will require are tail() and head(). tail() uses the drop method for lists which returns a list containing all elements except the first n elements. head() uses the first method for lists which returns the first element on the list. For more information, please refer to the following links: Extension functions: http://developer.android.com drop(): https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/drop.html first(): https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/first.html