Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,161,157 members, 7,845,814 topics. Date: Friday, 31 May 2024 at 04:28 AM

Kindly Solve This Bubblesort For Me - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Kindly Solve This Bubblesort For Me (795 Views)

Can Someone Kindly Help Me Correct This Error / Kindly Download My First Android Mobile Application / Please Kindly Help With This Html/javascript Problem. (2) (3) (4)

(1) (Reply) (Go Down)

Kindly Solve This Bubblesort For Me by cruworld(m): 1:55pm On Apr 24, 2010
#include <iostream>
#include <iomanip>

void sort(int a[], int n);
using namespace std;

int main ()
{
    int a[] = {84,69,76,86,94,91};
    cout<<sort(a,6)<<endl;

         
        cin.get();
        return 0;
}
void sort(int a[], int n)
{
     int temp;
     for(int i = 1; i < n; i++)
     {
             for(int j = 0; j < n - i;j++)
             {
                     if(a[j] > a[j+1])
                     {
                     temp = a[j + 1];
                     a[j + 1] = a[j];
                     a[j] = temp;
                     }
                     }
                     }
                     return;
}
Re: Kindly Solve This Bubblesort For Me by chukxy: 4:56pm On Apr 25, 2010
@ poster, I am not c++ programmer, i think you made mistake in your sort function and have corrected it. Tried compiling it with c++ compiler
but there is syntax error in this line of code /* cout<<sort(a,6)<<endl; */; hence, I compiled it wth c and it worked. You can modify the function and correct the syntax error in c++ and it will work fine.






#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

void sort(int a[], int n);


int main ()
{
int a[] = {84,69,76,86,94,91};
sort(a,6);
int c;
for(c=0;c<6;c++)
{
printf("%d\n",a[c]);
}
_getche();
return 0;
}
void sort(int a[], int n)
{
int temp,i,j;
for(i = 0;i<n-1;i++)
for( j = n-1; j > i;j--)
{
if(a[j-1] > a[j])
{
temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
}


}

Cheers!
Re: Kindly Solve This Bubblesort For Me by Nobody: 9:28pm On Apr 25, 2010
I am an out-dated c++ programmer - but i do know some compilers use that endl - i think it has something to do with microsoft visual c++ 6.0
Gosh, i cannot fully remember jare, too much web programming don scatter my head small
Re: Kindly Solve This Bubblesort For Me by candylips(m): 11:21am On Apr 26, 2010
bubble sort is damn slow.
Re: Kindly Solve This Bubblesort For Me by cruworld(m): 11:38am On Apr 26, 2010
Thanks Guys for your contribution i finally solved it.

(1) (Reply)

Anybody Wanna Help Make A Game (java Or C# Programmers) / Good Programming Textbook / Nairaland Should Create An Application Platform For Easier Access

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.