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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
using namespace std;
int getInput(int data[], int capacity, int sentinal);
void bubblesort(int data[], int length);
void printArray(int data[], int length);
int main()
{ int c,s, length;
int data[100];
getInput(data, c, s);
bubblesort(data,length);
printArray(data,length);
return 0;
}
int getInput(int data[], int capacity, int sentinal)
{
int a, i=0;
while(i < capacity)
{
cout << "Enter number:";
cin >> a;
if(a==-1)
{
return 0;
}
else
{
data[i]=a;
i++;
}
}
/*sentinal= -1;
int i=0, int a;
cout<<"Enter the size of data";
cin>>capacity;
/*while(data[i] != -1)
{
for (i =0; i < capacity; i++)
{ cout << "Enter item : ";
cin >> data[i];
}
}*/
}
void bubblesort(int a[], int length)
{ int swap;
for(int i=1; i<length ; i++)
{ for( int j=0; j<(length-i);j++)
{ if( a[j] > a [j+1] )
{ swap=a[j];
a[j] = a[j+1];
a[j+1]=swap;
}
}
}
}
void printArray(int data[], int length)
{
cout << "Enter values from greatest to least" << endl ;
for(int i=0; i<length; i++)
{
cout << "The values are:";
}
}
|