SlideShare a Scribd company logo
1 of 4
Download to read offline
Please help with this JAVA Assignment and show output if you can please
Complete required scripts based on eclipse and troubleshoot the scripts until the tasks are done.
1. Implement linear-sort, merge-sort and quick-sort (write the code for them).
Solution
Linear or Insertion Sort
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
class LinearSort
{
public static void sort( int values[] )
{
int N = values.length;
int i, j, temp;
for (i = 1; i< N; i++)
{
j = i;
temp = values[i];
while (j > 0 && temp < values[j-1])
{
values[j] = values[j-1];
j = j-1;
}
values[j] = temp;
}
}
public static void main(String[] args)
{
Scanner scan = new Scanner( System.in );
int n, i;
System.out.println("Enter number of elements");
n = scan.nextInt();
int values[] = new int[n];
System.out.println(" Enter elements");
for (i = 0; i < n; i++)
values[i] = scan.nextInt();
sort(values);
System.out.println(" Sorted Elements");
for (i = 0; i < n; i++)
System.out.print(values[i]+" ");
System.out.println();
}
}
Output:
Enter number of elements
6
Enter elements
34 56 12 8 9 23
Sorted Elements
8 9 12 23 34 56
Merge Sort
import java.util.Scanner;
public class Mergesort
{
public static void mergesort(int[] a, int low, int high)
{
int N = high - low;
if (N <= 1)
return;
int mid = low + N/2;
mergesort(a, low, mid);
mergesort(a, mid, high);
int[] temp = new int[N];
int i = low, j = mid;
for (int k = 0; k < N; k++)
{
if (i == mid)
temp[k] = a[j++];
else if (j == high)
temp[k] = a[i++];
else if (a[j] pivot)
j--;
if (i <= j)
{
temp = values[i];
values[i] = values[j];
values[j] = temp;
i++;
j--;
}
}
if (low < j)
quickquicksort(values, low, j);
if (i < high)
quickquicksort(values, i, high);
}
public static void main(String[] args)
{
Scanner scan = new Scanner( System.in );
int n, i;
System.out.println("Enter number of elements");
n = scan.nextInt();
int values[] = new int[ n ];
System.out.println(" Enter elements");
for (i = 0; i < n; i++)
values[i] = scan.nextInt();
quicksort(values);
System.out.println(" qSorted Elements ");
for (i = 0; i < n; i++)
System.out.print(values[i]+" ");
System.out.println();
}
}
Output:
Enter number of elements
8
Enter elements
89 23 90 56 13 71 46 13
Sorted Elements
13 13 23 46 56 71 89 90

More Related Content

Similar to Please help with this JAVA Assignment and show output if you can ple.pdf

FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdfactocomputer
 
2 m2.w2.d1 - oop
2   m2.w2.d1 - oop2   m2.w2.d1 - oop
2 m2.w2.d1 - oopJustin Chen
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...MaruMengesha
 
Computer java programs
Computer java programsComputer java programs
Computer java programsADITYA BHARTI
 
UserInputHandlerjava package midterm2023 import javautil.pdf
UserInputHandlerjava package midterm2023 import javautil.pdfUserInputHandlerjava package midterm2023 import javautil.pdf
UserInputHandlerjava package midterm2023 import javautil.pdfadityknits
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab filesNitesh Dubey
 
Please implement in Java. comments would be appreciated 5.pdf
Please implement in Java. comments would be appreciated 5.pdfPlease implement in Java. comments would be appreciated 5.pdf
Please implement in Java. comments would be appreciated 5.pdffms12345
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsSunil Yadav
 
SolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdf
SolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdfSolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdf
SolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdfannaimobiles
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lecturesMSohaib24
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignmentashikul akash
 
java slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfjava slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfkokah57440
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksDoug Hawkins
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory archana singh
 
1.aimport java.util.Scanner;public class Diamond {   public st.pdf
1.aimport java.util.Scanner;public class Diamond {   public st.pdf1.aimport java.util.Scanner;public class Diamond {   public st.pdf
1.aimport java.util.Scanner;public class Diamond {   public st.pdfaparnatiwari291
 
Pj01 4-operators and control flow
Pj01 4-operators and control flowPj01 4-operators and control flow
Pj01 4-operators and control flowSasidharaRaoMarrapu
 

Similar to Please help with this JAVA Assignment and show output if you can ple.pdf (20)

FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdf
 
2 m2.w2.d1 - oop
2   m2.w2.d1 - oop2   m2.w2.d1 - oop
2 m2.w2.d1 - oop
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
UserInputHandlerjava package midterm2023 import javautil.pdf
UserInputHandlerjava package midterm2023 import javautil.pdfUserInputHandlerjava package midterm2023 import javautil.pdf
UserInputHandlerjava package midterm2023 import javautil.pdf
 
Pnno
PnnoPnno
Pnno
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
LAB1.docx
LAB1.docxLAB1.docx
LAB1.docx
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Please implement in Java. comments would be appreciated 5.pdf
Please implement in Java. comments would be appreciated 5.pdfPlease implement in Java. comments would be appreciated 5.pdf
Please implement in Java. comments would be appreciated 5.pdf
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
 
SolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdf
SolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdfSolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdf
SolutionSelection Sort after two iterations1 14 8 9 5 16 2 1.pdf
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
 
java slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfjava slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdf
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's Tricks
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
 
Programs of java
Programs of javaPrograms of java
Programs of java
 
1.aimport java.util.Scanner;public class Diamond {   public st.pdf
1.aimport java.util.Scanner;public class Diamond {   public st.pdf1.aimport java.util.Scanner;public class Diamond {   public st.pdf
1.aimport java.util.Scanner;public class Diamond {   public st.pdf
 
Pj01 4-operators and control flow
Pj01 4-operators and control flowPj01 4-operators and control flow
Pj01 4-operators and control flow
 

More from aroramobiles1

ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdfooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdfaroramobiles1
 
ood evening people. Ive been working on this code that sends a bur.pdf
ood evening people. Ive been working on this code that sends a bur.pdfood evening people. Ive been working on this code that sends a bur.pdf
ood evening people. Ive been working on this code that sends a bur.pdfaroramobiles1
 
Multiply. 0 072(10,000) Multiply. 317.02 middot 0.01 Write the nu.pdf
Multiply.  0 072(10,000)  Multiply.  317.02 middot 0.01  Write the nu.pdfMultiply.  0 072(10,000)  Multiply.  317.02 middot 0.01  Write the nu.pdf
Multiply. 0 072(10,000) Multiply. 317.02 middot 0.01 Write the nu.pdfaroramobiles1
 
Mitochondria and chloroplasts have small genomes becauseQuestion .pdf
Mitochondria and chloroplasts have small genomes becauseQuestion .pdfMitochondria and chloroplasts have small genomes becauseQuestion .pdf
Mitochondria and chloroplasts have small genomes becauseQuestion .pdfaroramobiles1
 
Meta-population theory and island biogeography theory are similar in .pdf
Meta-population theory and island biogeography theory are similar in .pdfMeta-population theory and island biogeography theory are similar in .pdf
Meta-population theory and island biogeography theory are similar in .pdfaroramobiles1
 
Java Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfJava Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfaroramobiles1
 
Kim’s revenue one week ago were $251 less than three times Janes rev.pdf
Kim’s revenue one week ago were $251 less than three times Janes rev.pdfKim’s revenue one week ago were $251 less than three times Janes rev.pdf
Kim’s revenue one week ago were $251 less than three times Janes rev.pdfaroramobiles1
 
I am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdfI am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdfaroramobiles1
 
How has television influenced the political process, specifically th.pdf
How has television influenced the political process, specifically th.pdfHow has television influenced the political process, specifically th.pdf
How has television influenced the political process, specifically th.pdfaroramobiles1
 
HISTORY Why is it called American revolutionSolutionThe .pdf
HISTORY Why is it called American revolutionSolutionThe .pdfHISTORY Why is it called American revolutionSolutionThe .pdf
HISTORY Why is it called American revolutionSolutionThe .pdfaroramobiles1
 
Explain what #include does in a source codeSolution Th.pdf
Explain what #include  does in a source codeSolution Th.pdfExplain what #include  does in a source codeSolution Th.pdf
Explain what #include does in a source codeSolution Th.pdfaroramobiles1
 
dNdS ratios reflect patterns of genetic divergence that have accumu.pdf
dNdS ratios reflect patterns of genetic divergence that have accumu.pdfdNdS ratios reflect patterns of genetic divergence that have accumu.pdf
dNdS ratios reflect patterns of genetic divergence that have accumu.pdfaroramobiles1
 
Discuss the complexity of problem definition and the importance of a.pdf
Discuss the complexity of problem definition and the importance of a.pdfDiscuss the complexity of problem definition and the importance of a.pdf
Discuss the complexity of problem definition and the importance of a.pdfaroramobiles1
 
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdfDefine the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdfaroramobiles1
 
Describe how the principle of consistency can be applied to interfac.pdf
Describe how the principle of consistency can be applied to interfac.pdfDescribe how the principle of consistency can be applied to interfac.pdf
Describe how the principle of consistency can be applied to interfac.pdfaroramobiles1
 
Chapter 8 was tough for me. When determining the lumber needs of the.pdf
Chapter 8 was tough for me. When determining the lumber needs of the.pdfChapter 8 was tough for me. When determining the lumber needs of the.pdf
Chapter 8 was tough for me. When determining the lumber needs of the.pdfaroramobiles1
 
{public int idata;data item (key) public double ddata;data item p.pdf
{public int idata;data item (key) public double ddata;data item p.pdf{public int idata;data item (key) public double ddata;data item p.pdf
{public int idata;data item (key) public double ddata;data item p.pdfaroramobiles1
 
You have been given a file that contains fields relating to CD infor.pdf
You have been given a file that contains fields relating to CD infor.pdfYou have been given a file that contains fields relating to CD infor.pdf
You have been given a file that contains fields relating to CD infor.pdfaroramobiles1
 
Write a java method named flipLines that accepts as its parameter a .pdf
Write a java method named flipLines that accepts as its parameter a .pdfWrite a java method named flipLines that accepts as its parameter a .pdf
Write a java method named flipLines that accepts as its parameter a .pdfaroramobiles1
 
Which of the following isare true regarding router operationA. R.pdf
Which of the following isare true regarding router operationA. R.pdfWhich of the following isare true regarding router operationA. R.pdf
Which of the following isare true regarding router operationA. R.pdfaroramobiles1
 

More from aroramobiles1 (20)

ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdfooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
 
ood evening people. Ive been working on this code that sends a bur.pdf
ood evening people. Ive been working on this code that sends a bur.pdfood evening people. Ive been working on this code that sends a bur.pdf
ood evening people. Ive been working on this code that sends a bur.pdf
 
Multiply. 0 072(10,000) Multiply. 317.02 middot 0.01 Write the nu.pdf
Multiply.  0 072(10,000)  Multiply.  317.02 middot 0.01  Write the nu.pdfMultiply.  0 072(10,000)  Multiply.  317.02 middot 0.01  Write the nu.pdf
Multiply. 0 072(10,000) Multiply. 317.02 middot 0.01 Write the nu.pdf
 
Mitochondria and chloroplasts have small genomes becauseQuestion .pdf
Mitochondria and chloroplasts have small genomes becauseQuestion .pdfMitochondria and chloroplasts have small genomes becauseQuestion .pdf
Mitochondria and chloroplasts have small genomes becauseQuestion .pdf
 
Meta-population theory and island biogeography theory are similar in .pdf
Meta-population theory and island biogeography theory are similar in .pdfMeta-population theory and island biogeography theory are similar in .pdf
Meta-population theory and island biogeography theory are similar in .pdf
 
Java Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfJava Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdf
 
Kim’s revenue one week ago were $251 less than three times Janes rev.pdf
Kim’s revenue one week ago were $251 less than three times Janes rev.pdfKim’s revenue one week ago were $251 less than three times Janes rev.pdf
Kim’s revenue one week ago were $251 less than three times Janes rev.pdf
 
I am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdfI am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdf
 
How has television influenced the political process, specifically th.pdf
How has television influenced the political process, specifically th.pdfHow has television influenced the political process, specifically th.pdf
How has television influenced the political process, specifically th.pdf
 
HISTORY Why is it called American revolutionSolutionThe .pdf
HISTORY Why is it called American revolutionSolutionThe .pdfHISTORY Why is it called American revolutionSolutionThe .pdf
HISTORY Why is it called American revolutionSolutionThe .pdf
 
Explain what #include does in a source codeSolution Th.pdf
Explain what #include  does in a source codeSolution Th.pdfExplain what #include  does in a source codeSolution Th.pdf
Explain what #include does in a source codeSolution Th.pdf
 
dNdS ratios reflect patterns of genetic divergence that have accumu.pdf
dNdS ratios reflect patterns of genetic divergence that have accumu.pdfdNdS ratios reflect patterns of genetic divergence that have accumu.pdf
dNdS ratios reflect patterns of genetic divergence that have accumu.pdf
 
Discuss the complexity of problem definition and the importance of a.pdf
Discuss the complexity of problem definition and the importance of a.pdfDiscuss the complexity of problem definition and the importance of a.pdf
Discuss the complexity of problem definition and the importance of a.pdf
 
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdfDefine the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
 
Describe how the principle of consistency can be applied to interfac.pdf
Describe how the principle of consistency can be applied to interfac.pdfDescribe how the principle of consistency can be applied to interfac.pdf
Describe how the principle of consistency can be applied to interfac.pdf
 
Chapter 8 was tough for me. When determining the lumber needs of the.pdf
Chapter 8 was tough for me. When determining the lumber needs of the.pdfChapter 8 was tough for me. When determining the lumber needs of the.pdf
Chapter 8 was tough for me. When determining the lumber needs of the.pdf
 
{public int idata;data item (key) public double ddata;data item p.pdf
{public int idata;data item (key) public double ddata;data item p.pdf{public int idata;data item (key) public double ddata;data item p.pdf
{public int idata;data item (key) public double ddata;data item p.pdf
 
You have been given a file that contains fields relating to CD infor.pdf
You have been given a file that contains fields relating to CD infor.pdfYou have been given a file that contains fields relating to CD infor.pdf
You have been given a file that contains fields relating to CD infor.pdf
 
Write a java method named flipLines that accepts as its parameter a .pdf
Write a java method named flipLines that accepts as its parameter a .pdfWrite a java method named flipLines that accepts as its parameter a .pdf
Write a java method named flipLines that accepts as its parameter a .pdf
 
Which of the following isare true regarding router operationA. R.pdf
Which of the following isare true regarding router operationA. R.pdfWhich of the following isare true regarding router operationA. R.pdf
Which of the following isare true regarding router operationA. R.pdf
 

Recently uploaded

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

Please help with this JAVA Assignment and show output if you can ple.pdf

  • 1. Please help with this JAVA Assignment and show output if you can please Complete required scripts based on eclipse and troubleshoot the scripts until the tasks are done. 1. Implement linear-sort, merge-sort and quick-sort (write the code for them). Solution Linear or Insertion Sort import java.util.*; import java.lang.*; import java.io.*; import java.util.Scanner; class LinearSort { public static void sort( int values[] ) { int N = values.length; int i, j, temp; for (i = 1; i< N; i++) { j = i; temp = values[i]; while (j > 0 && temp < values[j-1]) { values[j] = values[j-1]; j = j-1; } values[j] = temp; } } public static void main(String[] args) { Scanner scan = new Scanner( System.in ); int n, i; System.out.println("Enter number of elements"); n = scan.nextInt();
  • 2. int values[] = new int[n]; System.out.println(" Enter elements"); for (i = 0; i < n; i++) values[i] = scan.nextInt(); sort(values); System.out.println(" Sorted Elements"); for (i = 0; i < n; i++) System.out.print(values[i]+" "); System.out.println(); } } Output: Enter number of elements 6 Enter elements 34 56 12 8 9 23 Sorted Elements 8 9 12 23 34 56 Merge Sort import java.util.Scanner; public class Mergesort { public static void mergesort(int[] a, int low, int high) { int N = high - low; if (N <= 1) return; int mid = low + N/2; mergesort(a, low, mid); mergesort(a, mid, high); int[] temp = new int[N]; int i = low, j = mid; for (int k = 0; k < N; k++) { if (i == mid) temp[k] = a[j++];
  • 3. else if (j == high) temp[k] = a[i++]; else if (a[j] pivot) j--; if (i <= j) { temp = values[i]; values[i] = values[j]; values[j] = temp; i++; j--; } } if (low < j) quickquicksort(values, low, j); if (i < high) quickquicksort(values, i, high); } public static void main(String[] args) { Scanner scan = new Scanner( System.in ); int n, i; System.out.println("Enter number of elements"); n = scan.nextInt(); int values[] = new int[ n ]; System.out.println(" Enter elements"); for (i = 0; i < n; i++) values[i] = scan.nextInt(); quicksort(values); System.out.println(" qSorted Elements "); for (i = 0; i < n; i++) System.out.print(values[i]+" "); System.out.println(); } } Output:
  • 4. Enter number of elements 8 Enter elements 89 23 90 56 13 71 46 13 Sorted Elements 13 13 23 46 56 71 89 90