Total members 11894 |It is currently Fri Nov 22, 2024 2:35 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Well I'm kinda new to programming and since i didn't see this sort on this site I thought that I'd post mine. Just made this last night just to see if I could. If you see any errors please point them out.
cpp code
#include<iostream>

int* BubbleSort(int* a);

using namespace std;

void main()
{

int sort[10], i;
int* psort = 0;
psort = sort;

printf("Enter 10 numbers: \n");
for(i=0; i<10; i++) {
printf("%d: ", (i+1));
cin >> sort[i];
}

printf("\nBefore sorted: ");
for(i=0; i < 10; i++) {
printf("%d ", sort[i]);
}

printf("\n\n After Sorted: ");
psort = BubbleSort(psort);

for(i=0; i < 10; i++) {
printf("%d ", sort[i]);
}
printf("\n");
}

int* BubbleSort(int* a) {

int c = 0;
int d = 0;

do {
d = 0;
for(int b = 0; b < 9; b++) {
if(a[b] > a[b+1]) {
c = a[b];
a[b] = a[b+1];
a[b+1] = c;
d++;
}
}
}while(d);

return a;
}

This algorithm is one of the simplest and easiest to understand but it is very inefficient so I wouldn't use it for anything serious.
This sorts out 10 integers in an array and puts them from lowest to highest order.




Author:
Newbie
User avatar Posts: 2
Have thanks: 0 time

Thanks "Shimano" for your post :gOOd: :gOOd: :gOOd: :gOOd: .

About my self i made the bubble sort before by my self but i don;t know where the code gone :swoon: . thanks and keep sharing your work , i am sure it will be helpful to someone .

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : C++ Bubble Sort
 bidirectional bubble sort algorithm implementation java     -  
 Bubble Sort Algorithm Java Implementation Code-Sorting Array     -  
 Insertion Sort (C++)     -  
 Array sort     -  
 C++ Recursion Sort     -  
 C++ Selection Sort     -  
 sort words in c++     -  
 Library Sort     -  
 String Sort     -  
 selection sort     -  



Topic Tags

C++ Sorting






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com