Bubble sorting

hey i'm trying to make a c++ program of this but i don't know how to use the bubble sorting. i really need a program of this immediately. thank you for immediately response.

Write a C++ application that asks the user to enter 10 numbers. The program then stores those numbers in an Array. The program should display the Mean , Median, and Mode.

Mean is the average of the 10 numbers.
Median is the average of the 5th and the 6th numbers. (But you have to arrange the numbers in ascending order first using Bubble Sort before calculating the Median.)
Mode is the most frequent number among the 10 numbers.
Last edited on

This is not a homework site. We will not do your homework for you. Please provide some code and ask a question so we know exactly what you need help with.



http://mathbits.com/MathBits/CompSci/Arrays/Bubble.htm
Last edited on
Here's an example of Bubble Sort

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
 
int main()
{
  int array[100], n, c, d, swap;
 
  printf("Enter number of elements\n");
  scanf("%d", &n);
 
  printf("Enter %d integers\n", n);
 
  for (c = 0; c < n; c++)
    scanf("%d", &array[c]);
 
  for (c = 0 ; c < ( n - 1 ); c++)
  {
    for (d = 0 ; d < n - c - 1; d++)
    {
      if (array[d] > array[d+1]) /* For decreasing order use < */
      {
        swap       = array[d];
        array[d]   = array[d+1];
        array[d+1] = swap;
      }
    }
  }
 
  printf("Sorted list in ascending order:\n");
 
  for ( c = 0 ; c < n ; c++ )
     printf("%d\n", array[c]);
 
  return 0;
}


Link: http://www.programmingsimplified.com/c/source-code/c-program-bubble-sort
There was a bubble sort assignment in my CSC 138 class and the syntax went like this :


#include <iostream>
using namespace std;



template <class T>

//bubblesort (int array[], int size)

void BubbleSort(T A[], int N){

{

int i, j;

for (i = 0; i < N; i++)

for (j = i + 1; j < N; j++)

if (A[j] < A[i])

{

int buff;

bub = A[i];

A[i] = A[j];

A[j] = buff;

}

void main(){

int N[10];

for (int i=0; i<10; i++)

N[i]=rand();

}
another example
#include<iostream.h>
#include<conio.h>
using namespace std;

main()
{

int hold;
int array[5];
cout<<"Enter 5 numbers: "<<endl;
for(int i=0; i<5; i++)
{
cin>>array[i];
}
cout<<endl;
cout<<"Orignally entered array by the user is: "<<endl;

for(int j=0; j<5; j++)
{
cout<<array[j];
cout<<endl;
}
cout<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
if(array[j]>array[j+1])
{
hold=array[j];
array[j]=array[j+1];
array[j+1]=hold;
}
}
}
cout<<"Sorted Array is: "<<endl;
for(int i=0; i<5; i++)
{
cout<<array[i]<<endl;
}

getch();
}
@mutexe
LOL, you tried to get OP to use his brain and discourage simple code dumps.

Sorry man, I've been where you are, and there will always be someone to prove me wrong.

BTW, http://www.cplusplus.com/faq/sequences/sequencing/sort-algorithms/bubble-sort/
Last edited on
Topic archived. No new replies allowed.