arturr's Profile User Rating:

Reputation: 1 Apprentice
Group:
Members
Active Posts:
21 (0.03 per day)
Joined:
09-February 12
Profile Views:
697
Last Active:
Feb 22 2013 06:26 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
arturr has not set their status

1. In Topic: Program to compare sorting algorithms

Posted 23 Sep 2012

I got it to work. Can you guys have a look at my results and let me know if they look okey ?

Best case = sorted list of 2000 integers
Random = 2000 integers in random order
Worst case = list of 2000 integer in revers order

Bubble Sort: Exchanges: 1999000 Comparisons: 1999000 In worst case.
Bubble Sort: Exchanges: 989001 Comparisons: 1995259 With random ordering.
Bubble Sort: Exchanges: 0 Comparisons: 1999 In best case.

Selection Sort: Exchanges: 1000 Comparisons: 1999000 In worst case.
Selection Sort: Exchanges: 1993 Comparisons: 1999000 With random ordering.
Selection Sort: Exchanges: 0 Comparisons: 1999000 In best case.

Insertion Sort: Exchanges: 1998999 Comparisons: 1998999 In worst case.
Insertion Sort: Exchanges: 989001 Comparisons: 989007 With random ordering.
Insertion Sort: Exchanges: 0 Comparisons: 1998 In best case.
2. In Topic: Recursive method sorting an array

Posted 18 Mar 2012

I'm not an expert but I don't see how it is a quicksort. It seems like it's recursive selection sort.
3. In Topic: Keeping arraylist in alpabetical order

Posted 29 Feb 2012

ok thank you very much for your help, somehow the code I copied from Ideone.com works, but it didn't work before. It was probably coping error.
4. In Topic: Keeping arraylist in alpabetical order

Posted 29 Feb 2012

sorry, here are all three

```import java.text.NumberFormat;

public class DVDCollection
{
private DVD[] collection;
private int count;
private double totalCost;
private double average;

public DVDCollection ()
{
collection = new DVD[0];
count = 0;
totalCost = 0.0;

}

public void addDVD (String title, String director, int year, double cost, boolean blueray)
{

DVD[] temp = new DVD[collection.length + 1];
int index = 0;
int i = 0;
for(;  0 < collection.length; i++)
{
if(collection[i].getTitle().compareTo(title)>0) {
temp[index++] = new DVD (title, director, year, cost, blueray);
break;
}

temp[index++] = collection[i];

}

for(; i < collection.length; i++){
temp[index++] = collection[i];
}
if(index != temp.length)
temp[index] = new DVD (title, director, year, cost, blueray);

collection = temp;
totalCost += cost;
average=totalCost/collection.length;
}

public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();

String report = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
report += "My DVD Collection\n\n";

report += "Number of DVDs: " + collection.length + "\n";
report += "Total cost: " + fmt.format(totalCost) + "\n";
report += "Average cost: " + average;

report += "\n\nDVD List:\n\n";

for (int i = 0; i < collection.length; i++)
report += collection[i] + "\n";

return report;
}

private void increaseSize ()
{
DVD[] temp = new DVD[collection.length * 2];

for (int dvd = 0; dvd < collection.length; dvd++)
temp[dvd] = collection[dvd];

collection = temp;
}
}

```

```import java.text.NumberFormat;

public class DVD
{
public String title, director;
private int year;
private double cost;
private boolean bluRay;

public DVD (String title, String director, int year, double cost,
boolean bluRay)
{
this.title = title;
this.director = director;
this.year = year;
this.cost = cost;
this.bluRay = bluRay;
}

public String getTitle(){
return title;
}

public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();

String description;

description = fmt.format(cost) + "\t" + year + "\t";
description += title + "\t" + director;

if (bluRay)
description += "\t" + "Blu-Ray";

return description;
}
}
```

```public class Movies
{

public static void main (String[] args)
{
DVDCollection movies = new DVDCollection();

movies.addDVD ("The Godfather", "Francis Ford Coppala", 1972, 24.95, true);
movies.addDVD ("District 9", "Neill Blomkamp", 2009, 19.95, false);
movies.addDVD ("Iron Man", "Jon Favreau", 2008, 15.95, false);
movies.addDVD ("Iron Man 2", "Jon Favreau", 2010, 22.99, false);
movies.addDVD ("Casablanca", "Michael Curtiz", 1942, 19.95, false);

System.out.println (movies);
}
}
```
5. In Topic: Keeping arraylist in alpabetical order

Posted 29 Feb 2012

```import java.text.NumberFormat;

public class DVDCollection
{
private DVD[] collection;
private int count;
private double totalCost;
private double average;

public DVDCollection ()
{
collection = new DVD[0];
count = 0;
totalCost = 0.0;

}

public void addDVD (String title, String director, int year, double cost, boolean blueray)
{

DVD[] temp = new DVD[collection.length + 1];
int index = 0;
int i = 0;
for(;  0 < collection.length; i++)
{
if(collection[i].getTitle().compareTo(title)>0) {
temp[index++] = new DVD (title, director, year, cost, blueray);
break;
}

temp[index++] = collection[i];

}

for(; i < collection.length; i++){
temp[index++] = collection[i];
}
if(index != temp.length)
temp[index] = new DVD (title, director, year, cost, blueray);

collection = temp;
totalCost += cost;
average=totalCost/collection.length;
}

public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();

String report = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
report += "My DVD Collection\n\n";

report += "Number of DVDs: " + collection.length + "\n";
report += "Total cost: " + fmt.format(totalCost) + "\n";
report += "Average cost: " + average;

report += "\n\nDVD List:\n\n";

for (int i = 0; i < collection.length; i++)
report += collection[i] + "\n";

return report;
}

private void increaseSize ()
{
DVD[] temp = new DVD[collection.length * 2];

for (int dvd = 0; dvd < collection.length; dvd++)
temp[dvd] = collection[dvd];

collection = temp;
}
}

```

Member Title:
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

E-mail:
Private

Friends

arturr hasn't added any friends yet.