Nov 9, 2012 at 5:56am UTC
/* By: Jacob */
#include <iostream>
using namespace std;
int descend(int *, int, int);
int main ()
{
int num[10];
int awn =1;
int x=0,i=0,t=0, a, b, c, size=10, z=0;
char numawn='y';
do{ // Load integer array
cout << "Please enter a integer number:" << endl;
cin >> num[x];
x++;
cout << "Would you like to enter another integer?" << endl << "y for yes n for no:" << endl;
cin >> numawn;
}while(numawn=='y');
for(t;t<x;t++) cout << num[t] << " "; //display integer array
descend(num,x,t);
for(t=0;t<x;t++) cout << num[t] << " " << endl;; //display integer array
//bubble sort descending
for(a=1; a<x; a++)
for(b=x-1; b>=a; b--) {
if(num[b-1] < num[b]) {
c = num[b-1];
num[b-1] = num[b];
num[b] = c;
}
}
for(t=0;t<x;t++) cout << num[t] << " " << endl; //display integer array
return 0;
}
int desend(int *num, int t, int x){
//bubble sort ascending
int a, b, c;
for(a=1; a<x; a++)
for(b=x-1; b>=a; b--) {
if(num[b-1] > num[b]) {
c = num[b-1];
num[b-1] = num[b];
num[b] = c;
}
}
return *num;
}
im trying to turn this bubble sort into a function that I can just call when I need it. Please help me.
Last edited on Nov 11, 2012 at 5:57pm UTC
Nov 9, 2012 at 6:26am UTC
What problem are you having?
Nov 9, 2012 at 6:31am UTC
When I try to compile the program it shows errors. I think it is because I am incorrectly passing the variables and array.
Nov 9, 2012 at 6:32am UTC
When you post code, surround it with [co de][/code] tags so it's easier to read.
What are the errors? Can't help you much without knowing what they are.
Nov 9, 2012 at 6:34am UTC
Well let me ask you this, how would you turn that bubble sort code into a function and what would the prototype be?