Question

Using C++, build a sorter that can rank a sequence of numbers in a descending order....

Using C++, build a sorter that can rank a sequence of numbers in a descending order. It should be able to process at least 2 types of data, for example the integer sequence and the double sequence.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

#include<iostream>

using namespace std;

template<class T>

void bubble(T a[], int n)

{

int i, j;

for(i=0;i<n-1;i++)

{

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

{

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

{

T element;

element = a[i];

a[i] = a[j];

a[j] = element;

}

}

}

}

int main()

{

int a[6]={1,2,3,4,4,3};

double b[4]={6.5, 1.7, 9.5, 166.5};

bubble(a,6);

cout<<"\nSorted Order Integers: ";

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

cout<<a[i]<<" ";

bubble(b,4);

cout<<"\nSorted Order Doubles: ";

for(int j=0;j<4;j++)

cout<<b[j]<<" ";

}

Add a comment
Know the answer?
Add Answer to:
Using C++, build a sorter that can rank a sequence of numbers in a descending order....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT