Please put effort into it, i really need solution!! Using the Coordinate Pairs c
ID: 670222 • Letter: P
Question
Please put effort into it, i really need solution!!
Using the Coordinate Pairs class code provided in the directory prob6, read in values from "input txt" to initialize the array and sort the array of objects using the quick sort algorithm learned in part 2. I've provided a pseudocode template for your main function to show how you should read in and write out the data. I've also provided all of the member functions for the class you require to adapt the quick sort algorithm to use these objects. However, you may choose to add your own public or private member functions if you think it will make your code cleaner and more elegant. Note: This is an implementation choice that will be based partially on the way you think, but also on how comfortable you are with C/C++. The only requirement is that if you change the class (i.e. add/change member functions), the class must still be an Abstract Data Type (ADT) after you are done. Therefore, you CANNOT remove any public member functions (do you understand why?). You will be sorting the objects in the array based on increasing Manhattan Distance between the coordinate pairs. The Manhattan Distance between two coordinate pairs, (a,b) and (c,d), is defined as the sum of the absolute distances between the points in both planes. In other words, the Manhattan Distance = |a-c| + |b-d|.Explanation / Answer
import java.util.*;
public class QuickSort
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the elements");
elements=s.nextInt();
private int array[];
private int length;
public void sort(int[] input Arr)
{
return;
}
this.array=inputArr;
length=inputArr.length;
quicksort(0,length-1);
}
private vioid quickSort(int lowerIndex,higherindex)
{
int i=lowerIndex;
int j=higherIndex;
int pivot=array(lowerIndex+(higherIndex-lowerIndex)/2);
while(i<=j)
{
while(array[i]<pivot)
{
i++;
}
while(array[j]>pivot)
{
j--;
}
if(i<=j)
{
exchangeNumbers(i,j);
i++;
j--;
}
}
if(lowerIndex<j)
quickSort(lowerIndex,j);
if(i<higherIndex)
quickSort(i,higherIndex);
}
private void exchangeNumbers(int i,int j)
{
int temp=array[i];
array[i]=array[j];
array[j]=temp;
}
public static void main(String args[])
{
QuickSort sorter=new QuickSort();
int [] input={elements};
sorter.sort(input);
for(int i:input)
{
System.out.println(i);
System.out.println(" ");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.