Hi there,
New to the forums and I hope to help out as much as I can. I have lurked for a bit, however this is my first post. Anyways, here goes.
Is the time complexity of this code O(n^2)?
|
Code:
|
public void placeLargest(int[] list, int N)
{
// N is how many of the largest items we want to find (N=3, find 3 largest)
int n = 0;
int largest, index;
int[] tempList = list;
while (n < N)//Pass through the array N times
{
largest = tempList[0];
index = 0;
for (int i = 0; i < tempList.length; i++)
{
if (tempList[i] > largest)
{
largest = tempList[i];
index = i;
}
}
tempList[index] = 0;
Nlargest.enqueue(largest);//Simlply place the value in a queue created earlier
n++;
}
} |
Thanks in advance for your help.