• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Sorting algorithms specially Bubble Sort

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iqbal,

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?

 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic