Total members 9950 | Gratitudes |It is currently Sat Feb 11, 2012 1:47 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: C++ Bubble Sort
PostPosted: Sun Sep 07, 2008 6:11 pm 
Offline
Newbie
User avatar

Joined: Sun Sep 07, 2008 2:09 am
Posts: 2
Has thanked: 0 time
Have thanks: 0 time

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.
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.


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: C++ Bubble Sort
PostPosted: Sun Sep 07, 2008 7:57 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 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 .

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 Library Sort  C++ examples  mileloader  1
 sort words in c++  C++ examples  msi_333  0
 Help with selection sort for strings?  C-C++  fmylifec  2
 Array sort  C++ examples  mileloader  0
 Sort a list  C++ examples  mileloader  0

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 2 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team