| | |
Bubble Sort
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Took about 10 seconds to find the answer here Here
Last edited by Ancient Dragon; May 8th, 2008 at 9:43 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
It's explained very well here
If you know some c++, it won't be too hard to write.
Come back if you have problems (and code)
If you know some c++, it won't be too hard to write.
Come back if you have problems (and code)
Last edited by niek_e; May 8th, 2008 at 9:43 am.
The bubble sort is probably the very easiest sort algorithm there is. What is so difficult to understand about this:
I don't really use the above algorithm, but this one
And in C++ you can do it in just one line: But I doubt this is a satisfactory solution to your assignment.
C++ Syntax (Toggle Plain Text)
for (i=0; i<n-1; i++) { for (j=0; j<n-1-i; j++) if (a[j+1] < a[j]) { /* compare the two neighbors */ tmp = a[j]; /* swap a[j] and a[j+1] */ a[j] = a[j+1]; a[j+1] = tmp; } }
I don't really use the above algorithm, but this one
C++ Syntax (Toggle Plain Text)
for(int i = 0; i < n-1; i++) { for(int j = 0; i < n; j++) { if( a[i] < a[j] ) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } } }
And in C++ you can do it in just one line: But I doubt this is a satisfactory solution to your assignment.
C++ Syntax (Toggle Plain Text)
vector<int> array; // fill array is not shown // // now sort it std::sort(array.begin(),array.end());
Last edited by Ancient Dragon; May 8th, 2008 at 10:10 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
> What is so difficult to understand about this:
Is that a trick question? Of course it's difficult to understand if you haven't learned how it works yet.
Edward learned long ago that just because something is easy for her, it's not easy for everyone else, and vice versa.
Is that a trick question? Of course it's difficult to understand if you haven't learned how it works yet.
Edward learned long ago that just because something is easy for her, it's not easy for everyone else, and vice versa. If at first you don't succeed, keep on sucking until you do succeed.
Yaeh!!!! I have seen all that maybe I just dont want to understand it but honestly I would be lieying I I say I understand all o that, I just wish to know why
for (i=0; i<n-1; i++) {for (j=0; j<n-1-i; j++) are we substracting 1 and - 1 - i what does that mean, if Dragon U can be kind enough to explain that to me, I would go home and rest Some people get so rich they lose all respect for humanity. That's how rich I want to be.
•
•
•
•
I don't really use the above algorithm, but this one
C++ Syntax (Toggle Plain Text)
for(int i = 0; i < n-1; i++) { for(int j = 0; i < n; j++) { if( a[i] < a[j] ) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } } }
for(int j = 0; i < n; j++) be: for(int j = 0; j< n; j++) Or else you will get out of array-boundary => crash? Last edited by niek_e; May 8th, 2008 at 10:26 am.
![]() |
Similar Threads
- bubble sort function w/ array (C++)
- How do i change this JAVA Insertion sort object to Bubble Sort object (Java)
- Bubble Sort of a file of records in Pascal pls (Pascal and Delphi)
- simplified bubble sort c++ (C++)
- Bubble sort & File output jibrish errors??? (C)
Other Threads in the C++ Forum
- Previous Thread: Read File>>>>
- Next Thread: Data base connection with c++
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion count data delete deploy dll download dynamic dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






