GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Sep-2005, 23:12
sasuke101 sasuke101 is offline
New Member
 
Join Date: Sep 2005
Posts: 24
sasuke101 is on a distinguished road

need help with bubble sort for c++


I am look for documentation on writing a class for a bubblesort method and most of my books have nothing on it. can anyone point me in a direction or book or site that can help me do this project

thank you
  #2  
Old 20-Sep-2005, 23:25
Guidelines Plz Guidelines Plz is offline
Junior Member
 
Join Date: Sep 2005
Posts: 87
Guidelines Plz is on a distinguished road

Re: need help with bubble sort for c++


http://google.com for "Bubble Sort"
__________________

Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with.
  #3  
Old 21-Sep-2005, 20:12
Zorachus's Avatar
Zorachus Zorachus is offline
Junior Member
 
Join Date: Jul 2005
Posts: 58
Zorachus will become famous soon enough

Re: need help with bubble sort for c++


I normally wouldn't do this (you should write your own code) but I happened to have this laying around from when I was bored one night.

CPP / C++ / C Code:
#include <iostream>
#include <String>
#include <stdlib.h>
#include <iomanip>
using namespace std;
int main(){
string tosort[50], swap;
int a,b,c,d; //a= name input number, b= for loop(s), c= for loops(s) d= for loop(s) //
cout << "How many names would you like to input? ";
cin >> a;

cout << "Input " << a << " names." << endl;
for (d=0; d<a; d++)
    {
    cin >> tosort[d];
    }
system ("CLS");
for (b=a; b>=0; b--)
    {
    for (c=0; c<(a-1); c++)
    {
         if (tosort[c] > tosort[c+1])
        {
        swap = tosort[c];
        tosort[c] = tosort[c+1];
        tosort[c+1] = swap;
        }
    }
    }
for (d=0; d<a; d++)
    {
    cout << tosort[d] << endl;
    }
system ("pause");
}



You could also use pointers to eliminate the need for the swap variable, but when I wrote this, I didn't know how, and I don't feel like modifying it. Pretty simple, eh?
__________________
Pursue everything!

P.S. This is what you would get at some point in the alphabet with the removal of the Q and R.
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge sort on a linked list Temujin_12 C++ Forum 1 06-Mar-2008 20:33
Help with a bucket sort please. glulu76 C++ Forum 11 18-Apr-2005 15:33
[GIM] gim.h dsmith C Programming Language 0 18-Jan-2005 08:48
insert sort saphir55 C Programming Language 4 06-Dec-2004 14:00
help with Sort arrays/Size justachessgame C Programming Language 1 12-Nov-2004 23:46

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:56.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.