SlideShare a Scribd company logo
1 of 2
Download to read offline
write a program that given a list of 20 integers, sorts them according to insert sort. java
Solution
public class InsertionSort {
/**
* method to sort the array elements using insertion sorts *
*
* @param array
* @return
*/
public static int[] insertionSort(int array[]) {
int n = array.length;
for (int j = 1; j < n; j++) {
int key = array[j];
int i = j - 1;
while ((i > -1) && (array[i] > key)) {
array[i + 1] = array[i];
i--;
}
array[i + 1] = key;
}
return array;
}
/**
* method to print the array elements
*
* @param input
*/
private static void printNumbers(int[] input) {
for (int i = 0; i < input.length; i++) {
System.out.print(input[i] + ", ");
}
System.out.println(" ");
}
/**
* @param args
*/
public static void main(String[] args) {
int[] input = { 3, 26, 67, 35, 9, -6, 43, 82, 10, 54, 14, 22, 21, 32,
121, 231, 12, 98, 77, 65 };
System.out.println("Before Sorting");
printNumbers(input);
input = insertionSort(input);
System.out.println("Before Sorting");
printNumbers(input);
}
}
OUTPUT:
Before Sorting
3, 26, 67, 35, 9, -6, 43, 82, 10, 54, 14, 22, 21, 32, 121, 231, 12, 98, 77, 65,
Before Sorting
-6, 3, 9, 10, 12, 14, 21, 22, 26, 32, 35, 43, 54, 65, 67, 77, 82, 98, 121, 231,

More Related Content

Similar to write a program that given a list of 20 integers, sorts them accordi.pdf

Hi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfHi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfanujsharmaanuj14
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docxdavinci54
 
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfdeepua8
 
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfI am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfRAJATCHUGH12
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2Ankit Gupta
 
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdfarihantelehyb
 
Nested For Loops and Class Constants in Java
Nested For Loops and Class Constants in JavaNested For Loops and Class Constants in Java
Nested For Loops and Class Constants in JavaPokequesthero
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfarishmarketing21
 
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
 PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdfapexelectronices01
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfarri2009av
 
Design your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdfDesign your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdfprajeetjain
 
Operators
OperatorsOperators
Operatorsvvpadhu
 
import java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfimport java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfapoorvikamobileworld
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdffonecomp
 

Similar to write a program that given a list of 20 integers, sorts them accordi.pdf (20)

Hi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfHi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docx
 
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
 
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfI am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
 
Nested For Loops and Class Constants in Java
Nested For Loops and Class Constants in JavaNested For Loops and Class Constants in Java
Nested For Loops and Class Constants in Java
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdf
 
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
 PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
C programs
C programsC programs
C programs
 
Array list
Array listArray list
Array list
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
Design your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdfDesign your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdf
 
Operators
OperatorsOperators
Operators
 
import java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfimport java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdf
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
 

More from armcomputers

Homework 3 P11Is this relation a function    (Write either Yes.pdf
Homework 3 P11Is this relation a function    (Write either Yes.pdfHomework 3 P11Is this relation a function    (Write either Yes.pdf
Homework 3 P11Is this relation a function    (Write either Yes.pdfarmcomputers
 
i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfarmcomputers
 
Find Tukey-Kramer resultsa. Group 1 to Group 2 Different Not D.pdf
Find Tukey-Kramer resultsa. Group 1 to Group 2 Different  Not D.pdfFind Tukey-Kramer resultsa. Group 1 to Group 2 Different  Not D.pdf
Find Tukey-Kramer resultsa. Group 1 to Group 2 Different Not D.pdfarmcomputers
 
Female copperhead snakes have the ability to reproduce both sexually.pdf
Female copperhead snakes have the ability to reproduce both sexually.pdfFemale copperhead snakes have the ability to reproduce both sexually.pdf
Female copperhead snakes have the ability to reproduce both sexually.pdfarmcomputers
 
Explain some of the commonly held misconceptions about cloning. Why .pdf
Explain some of the commonly held misconceptions about cloning. Why .pdfExplain some of the commonly held misconceptions about cloning. Why .pdf
Explain some of the commonly held misconceptions about cloning. Why .pdfarmcomputers
 
Describe nN when the number of positive divisors of n is i) p2 for .pdf
Describe nN when the number of positive divisors of n is i) p2 for .pdfDescribe nN when the number of positive divisors of n is i) p2 for .pdf
Describe nN when the number of positive divisors of n is i) p2 for .pdfarmcomputers
 
Describe one derived trait in humans (Homo sapiens).SolutionThe.pdf
Describe one derived trait in humans (Homo sapiens).SolutionThe.pdfDescribe one derived trait in humans (Homo sapiens).SolutionThe.pdf
Describe one derived trait in humans (Homo sapiens).SolutionThe.pdfarmcomputers
 
Consider the table below How many featuresattributes are in this s.pdf
Consider the table below  How many featuresattributes are in this s.pdfConsider the table below  How many featuresattributes are in this s.pdf
Consider the table below How many featuresattributes are in this s.pdfarmcomputers
 
Chickens vary in color. Black and white color variation can be traced.pdf
Chickens vary in color. Black and white color variation can be traced.pdfChickens vary in color. Black and white color variation can be traced.pdf
Chickens vary in color. Black and white color variation can be traced.pdfarmcomputers
 
{c}Problem Run For Charity (charityrun.c)Charity Runs are a pop.pdf
{c}Problem Run For Charity (charityrun.c)Charity Runs are a pop.pdf{c}Problem Run For Charity (charityrun.c)Charity Runs are a pop.pdf
{c}Problem Run For Charity (charityrun.c)Charity Runs are a pop.pdfarmcomputers
 
Why is the 16S rRNA gene a preferred marker for the identification, .pdf
Why is the 16S rRNA gene a preferred marker for the identification, .pdfWhy is the 16S rRNA gene a preferred marker for the identification, .pdf
Why is the 16S rRNA gene a preferred marker for the identification, .pdfarmcomputers
 
Why do SSDs benefit from a scheduler like noopSolutionThe def.pdf
Why do SSDs benefit from a scheduler like noopSolutionThe def.pdfWhy do SSDs benefit from a scheduler like noopSolutionThe def.pdf
Why do SSDs benefit from a scheduler like noopSolutionThe def.pdfarmcomputers
 
which of the following types of orgnisms possess the enzyme catalase.pdf
which of the following types of orgnisms possess the enzyme catalase.pdfwhich of the following types of orgnisms possess the enzyme catalase.pdf
which of the following types of orgnisms possess the enzyme catalase.pdfarmcomputers
 
Which of the five factors of production is most important for creati.pdf
Which of the five factors of production is most important for creati.pdfWhich of the five factors of production is most important for creati.pdf
Which of the five factors of production is most important for creati.pdfarmcomputers
 
What is the good producing business What is the good producing.pdf
What is the good producing business What is the good producing.pdfWhat is the good producing business What is the good producing.pdf
What is the good producing business What is the good producing.pdfarmcomputers
 
What is the future of PKI Acceptance of PKI solutions—and product s.pdf
What is the future of PKI Acceptance of PKI solutions—and product s.pdfWhat is the future of PKI Acceptance of PKI solutions—and product s.pdf
What is the future of PKI Acceptance of PKI solutions—and product s.pdfarmcomputers
 
An easy temperament is best characterized asoptionshigh so.pdf
An easy temperament is best characterized asoptionshigh so.pdfAn easy temperament is best characterized asoptionshigh so.pdf
An easy temperament is best characterized asoptionshigh so.pdfarmcomputers
 
A protein that was isolated by a team of university scien4sts is sus.pdf
A protein that was isolated by a team of university scien4sts is sus.pdfA protein that was isolated by a team of university scien4sts is sus.pdf
A protein that was isolated by a team of university scien4sts is sus.pdfarmcomputers
 
A laser beam strikes one end of a slab of material of length L = 42..pdf
A laser beam strikes one end of a slab of material of length L = 42..pdfA laser beam strikes one end of a slab of material of length L = 42..pdf
A laser beam strikes one end of a slab of material of length L = 42..pdfarmcomputers
 
4. Communicate Carla gathered 328 sea-shells. Daniel gathered 176 .pdf
4. Communicate Carla gathered 328 sea-shells. Daniel gathered 176 .pdf4. Communicate Carla gathered 328 sea-shells. Daniel gathered 176 .pdf
4. Communicate Carla gathered 328 sea-shells. Daniel gathered 176 .pdfarmcomputers
 

More from armcomputers (20)

Homework 3 P11Is this relation a function    (Write either Yes.pdf
Homework 3 P11Is this relation a function    (Write either Yes.pdfHomework 3 P11Is this relation a function    (Write either Yes.pdf
Homework 3 P11Is this relation a function    (Write either Yes.pdf
 
i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdf
 
Find Tukey-Kramer resultsa. Group 1 to Group 2 Different Not D.pdf
Find Tukey-Kramer resultsa. Group 1 to Group 2 Different  Not D.pdfFind Tukey-Kramer resultsa. Group 1 to Group 2 Different  Not D.pdf
Find Tukey-Kramer resultsa. Group 1 to Group 2 Different Not D.pdf
 
Female copperhead snakes have the ability to reproduce both sexually.pdf
Female copperhead snakes have the ability to reproduce both sexually.pdfFemale copperhead snakes have the ability to reproduce both sexually.pdf
Female copperhead snakes have the ability to reproduce both sexually.pdf
 
Explain some of the commonly held misconceptions about cloning. Why .pdf
Explain some of the commonly held misconceptions about cloning. Why .pdfExplain some of the commonly held misconceptions about cloning. Why .pdf
Explain some of the commonly held misconceptions about cloning. Why .pdf
 
Describe nN when the number of positive divisors of n is i) p2 for .pdf
Describe nN when the number of positive divisors of n is i) p2 for .pdfDescribe nN when the number of positive divisors of n is i) p2 for .pdf
Describe nN when the number of positive divisors of n is i) p2 for .pdf
 
Describe one derived trait in humans (Homo sapiens).SolutionThe.pdf
Describe one derived trait in humans (Homo sapiens).SolutionThe.pdfDescribe one derived trait in humans (Homo sapiens).SolutionThe.pdf
Describe one derived trait in humans (Homo sapiens).SolutionThe.pdf
 
Consider the table below How many featuresattributes are in this s.pdf
Consider the table below  How many featuresattributes are in this s.pdfConsider the table below  How many featuresattributes are in this s.pdf
Consider the table below How many featuresattributes are in this s.pdf
 
Chickens vary in color. Black and white color variation can be traced.pdf
Chickens vary in color. Black and white color variation can be traced.pdfChickens vary in color. Black and white color variation can be traced.pdf
Chickens vary in color. Black and white color variation can be traced.pdf
 
{c}Problem Run For Charity (charityrun.c)Charity Runs are a pop.pdf
{c}Problem Run For Charity (charityrun.c)Charity Runs are a pop.pdf{c}Problem Run For Charity (charityrun.c)Charity Runs are a pop.pdf
{c}Problem Run For Charity (charityrun.c)Charity Runs are a pop.pdf
 
Why is the 16S rRNA gene a preferred marker for the identification, .pdf
Why is the 16S rRNA gene a preferred marker for the identification, .pdfWhy is the 16S rRNA gene a preferred marker for the identification, .pdf
Why is the 16S rRNA gene a preferred marker for the identification, .pdf
 
Why do SSDs benefit from a scheduler like noopSolutionThe def.pdf
Why do SSDs benefit from a scheduler like noopSolutionThe def.pdfWhy do SSDs benefit from a scheduler like noopSolutionThe def.pdf
Why do SSDs benefit from a scheduler like noopSolutionThe def.pdf
 
which of the following types of orgnisms possess the enzyme catalase.pdf
which of the following types of orgnisms possess the enzyme catalase.pdfwhich of the following types of orgnisms possess the enzyme catalase.pdf
which of the following types of orgnisms possess the enzyme catalase.pdf
 
Which of the five factors of production is most important for creati.pdf
Which of the five factors of production is most important for creati.pdfWhich of the five factors of production is most important for creati.pdf
Which of the five factors of production is most important for creati.pdf
 
What is the good producing business What is the good producing.pdf
What is the good producing business What is the good producing.pdfWhat is the good producing business What is the good producing.pdf
What is the good producing business What is the good producing.pdf
 
What is the future of PKI Acceptance of PKI solutions—and product s.pdf
What is the future of PKI Acceptance of PKI solutions—and product s.pdfWhat is the future of PKI Acceptance of PKI solutions—and product s.pdf
What is the future of PKI Acceptance of PKI solutions—and product s.pdf
 
An easy temperament is best characterized asoptionshigh so.pdf
An easy temperament is best characterized asoptionshigh so.pdfAn easy temperament is best characterized asoptionshigh so.pdf
An easy temperament is best characterized asoptionshigh so.pdf
 
A protein that was isolated by a team of university scien4sts is sus.pdf
A protein that was isolated by a team of university scien4sts is sus.pdfA protein that was isolated by a team of university scien4sts is sus.pdf
A protein that was isolated by a team of university scien4sts is sus.pdf
 
A laser beam strikes one end of a slab of material of length L = 42..pdf
A laser beam strikes one end of a slab of material of length L = 42..pdfA laser beam strikes one end of a slab of material of length L = 42..pdf
A laser beam strikes one end of a slab of material of length L = 42..pdf
 
4. Communicate Carla gathered 328 sea-shells. Daniel gathered 176 .pdf
4. Communicate Carla gathered 328 sea-shells. Daniel gathered 176 .pdf4. Communicate Carla gathered 328 sea-shells. Daniel gathered 176 .pdf
4. Communicate Carla gathered 328 sea-shells. Daniel gathered 176 .pdf
 

Recently uploaded

When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxRugvedSathawane
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxCeline George
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfNirmal Dwivedi
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonhttgc7rh9c
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 

write a program that given a list of 20 integers, sorts them accordi.pdf

  • 1. write a program that given a list of 20 integers, sorts them according to insert sort. java Solution public class InsertionSort { /** * method to sort the array elements using insertion sorts * * * @param array * @return */ public static int[] insertionSort(int array[]) { int n = array.length; for (int j = 1; j < n; j++) { int key = array[j]; int i = j - 1; while ((i > -1) && (array[i] > key)) { array[i + 1] = array[i]; i--; } array[i + 1] = key; } return array; } /** * method to print the array elements * * @param input */ private static void printNumbers(int[] input) { for (int i = 0; i < input.length; i++) { System.out.print(input[i] + ", "); } System.out.println(" "); }
  • 2. /** * @param args */ public static void main(String[] args) { int[] input = { 3, 26, 67, 35, 9, -6, 43, 82, 10, 54, 14, 22, 21, 32, 121, 231, 12, 98, 77, 65 }; System.out.println("Before Sorting"); printNumbers(input); input = insertionSort(input); System.out.println("Before Sorting"); printNumbers(input); } } OUTPUT: Before Sorting 3, 26, 67, 35, 9, -6, 43, 82, 10, 54, 14, 22, 21, 32, 121, 231, 12, 98, 77, 65, Before Sorting -6, 3, 9, 10, 12, 14, 21, 22, 26, 32, 35, 43, 54, 65, 67, 77, 82, 98, 121, 231,