Hey Guys......Go to My Blog To Get Bubble Sorting Code in c++...The Code is Very Simple And i Wrote it Just For understanding How Bubble Sorting Works ...For Any Assistance related To any code In C++,You Can Ask Me On My Blog :) http://codesinvisualc.blogspot.com/
I don't know much about CodeMonkey's programming skill, but I can't say anyone called him a smart programmer in this thread. There's no need to get defensive.
The problem with your code is that teaches some really bad habits. <iostream.h> has been deprecated (use <iostream> instead, note that there is no .h), and void main() was never standards-compliant (and g++, one of the world's most used compilers will not compile it, demanding that the type be changed to int). In the example above the bubble sort, you're using C strings when C++ strings (std::string from <string>) are a much safer alternative. Now, if this were C, then the use of char[]s as strings would be perfectly fine. However, C++ calls for a different set of ideals and to that end offers a different set of facilities.
guys you are right ......i should use iostream instead of adding up .h..the purpose of the code was just to give an overview of algo how bubble sorting works..thats why i used integer array for simplicity.once u know how to handle with them,then the next step is to learn about strings or char arrays using string library.....once you get an idea how to make algo n pseudo-code,then standards are not a big deal for some to get...:)
Actually, learning proper coding standards should be the priority. Any algorithm (including pseudocode) can be found on Wikipedia or after a quick google search. Proper coding is something you have to learn at the start, as unlearning bad habits is very, very difficult. Now if you'll excuse me, I'll be off declaring some global variables in a header file.
You should really have a 'while' loop on the outside of your inner 'for' loop which just tests if anything changed (i.e. if the array is now sorted or not).
If I fed a 4000-element array into your algorithm that was already sorted, do you know how many times your 'if' statement would have to execute before it was able to confirm that?
Hint: 15,992,000 ;)
Regards, keineahnung
*Edit*
Otherwise your code looks fine. Keep at it :)