import java.util.*; public class vectorSelection { public static voidmain(String
ID: 3619382 • Letter: I
Question
import java.util.*;public class vectorSelection
{
public static voidmain(String [] args)
{
Vector<String> b = new Vector<String>();
b.addElement("Arron");
b.addElement("Zed");
b.addElement("James");
b.addElement("Shayne");
b.addElement("Harry");
b.addElement("Colon");
b.addElement("Bea");
b.addElement("Francis");
System.out.println("Vector values before sorting:");
for(int i = 0; i < b.size(); i++)
System.out.print(b.elementAt(i) + " ");
System.out.println();
System.out.println("Vector values after sorting:");
selectionSort(b,b.size());
}
public static voidbubbleSort(Vector<String> b, int length){
boolean swapped = true;
// Setup our outer loop for detecting if a swap was made
while (swapped) {
swapped = false;
for(int i=0; i < length - 1; i++)
{
if(b.elementAt(i).compareTo(b.elementAt(i+ 1)) > 0)
{
String temp = b.elementAt(i);
b.setElementAt(b.elementAt(i+1),i);
b.setElementAt(temp,i+1);
swapped = true;
}
}
}
// After all sorting is finished, just list all the items in thearray.
for(int i = 0; i < b.size(); i++){
System.out.println(b.elementAt(i));
}
}
public static voidselectionSort(Vector<String> b, int length)
{
int index;
int smallestIndex;
int minIndex;
String temp = "";
int compCounter = 0,assignCounter = 0;
for (index = 0; index <length - 1; index++)
{
smallestIndex = index;
for(minIndex = index + 1; minIndex < length; minIndex++){
if(b.elementAt(minIndex).compareTo(b.elementAt(smallestIndex))>0)
smallestIndex = minIndex;
}
temp= b.elementAt(smallestIndex);
b.setElementAt(b.elementAt(smallestIndex), index);
b.setElementAt(temp, index);
}
for(int i = 0; i < b.size(); i++){
System.out.println(b.elementAt(i));
}
}
}
having a problem with the output... i get this output...can some1fix this plsssssss
output:
Vector values before sorting:
Arron Zed James Shayne Harry Colon Bea Francis
Vector values after sorting:
Zed
Zed
Shayne
Shayne
Harry
Francis
Francis
Francis