posted 13 years ago

I have to work on implementing sort algorithms in a Java. These are:

1- Bubble Sort.

2- Quick Sort.

3- and Shell sort.

I think I can handle the 2nd and 3rd one but I am clueless about the 1st one.

Is there someone to help me out?

1- Bubble Sort.

2- Quick Sort.

3- and Shell sort.

I think I can handle the 2nd and 3rd one but I am clueless about the 1st one.

Is there someone to help me out?

-----<br />If you think education is expensive, try ignorance.

posted 13 years ago

Homework time again!

Well, I'm rather sure your course notes or text has a pseudo-code algorithm for Bubble-sort. Even if its missing, a Google search is definitely able to help you get it, then you merely need to implement the algorithm into Java code.

Well, I'm rather sure your course notes or text has a pseudo-code algorithm for Bubble-sort. Even if its missing, a Google search is definitely able to help you get it, then you merely need to implement the algorithm into Java code.

SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8

posted 13 years ago

Don't say it's Data Structures and Algorithms related subject. I am also currently studying in that subject in MSCS. But in my master course, I do not need to implement them at all. Rather I have to analyze the running time and detailed worst-case, average-case and best-case running of each of them...

I do miss the time when I had to implement them in Java, when I was in bachelor course... But, Iqbal Ali, don't be discourage... As Cheng Wei Lee suggested, you'd better learn with Pseudocode from the textbook and implement them in Java... Just concentrate on understanding how they work, then you'll be able to beat it...

I do miss the time when I had to implement them in Java, when I was in bachelor course... But, Iqbal Ali, don't be discourage... As Cheng Wei Lee suggested, you'd better learn with Pseudocode from the textbook and implement them in Java... Just concentrate on understanding how they work, then you'll be able to beat it...

Co-author of SCMAD Exam Guide, Author of JMADPlus

SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0

posted 13 years ago

Bubble sort is named "bubble" because the largest value (or the smallest value, depending on whther you use < or > in your comparison) will float to the top of the list, like a bubble in a tank of water.

Assume you have a list of numbers, a, b, and c. The bubble sort is a variation on a swap - you compare two numbers, if a > b, then swap a & b. Next, compare (the new) b to c. At the end of the first iteration, the largest value will be at the top of the list. Simply start at the bottom of the list, and do it again. You are done when you pass through the list and no swaps take place.

There are several variation on it to enhance processing time - such as:

the first time through, loop n times, where n is the number of items in the list - 1. Next time, loop n-2 times (because you know that the largest value is already at the top, there is no need to compare it and waste the cycles). I will leave you to discover the other variations.

Good luck!

Assume you have a list of numbers, a, b, and c. The bubble sort is a variation on a swap - you compare two numbers, if a > b, then swap a & b. Next, compare (the new) b to c. At the end of the first iteration, the largest value will be at the top of the list. Simply start at the bottom of the list, and do it again. You are done when you pass through the list and no swaps take place.

There are several variation on it to enhance processing time - such as:

the first time through, loop n times, where n is the number of items in the list - 1. Next time, loop n-2 times (because you know that the largest value is already at the top, there is no need to compare it and waste the cycles). I will leave you to discover the other variations.

Good luck!

posted 13 years ago

Iqbal,

Please check this site

hth,

mw

Please check this site

hth,

mw

Originally posted by Iqbal Ali:

I have to work on implementing sort algorithms in a Java. These are:

1- Bubble Sort.

2- Quick Sort.

3- and Shell sort.

I think I can handle the 2nd and 3rd one but I am clueless about the 1st one.

Is there someone to help me out?

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |