Generic bubble sort in C

Today we Learn about sorting technique in  C for example:- How to create a Generic Bubble sort in C.

How to create a Generic Bubble Sorting in C

   #include <iostream>

using namespace std;


template <class X>

void bubble(X *data, intsize)


{

register inta, b;

X t;

for(a=1; a < size; a++)

for(b= size1; b >=
a; b–)

if(data[b1] > data[b])


{

t = data[b1];


data[b1] = data[b];

data[b] = t;


}


}

intmain()


{

inti[] = {3, 2, 5, 6, 1, 8, 9,3, 6, 9};

double d[] = {1.2, 5.5, 2.2, 3.3};

int j;


bubble(i, 10); // sort ints


    bubble(d, 4); // sort doubles

for(j=0; j<10; j++)

cout<< i[j] << ‘ ‘;


     cout << endl;

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


cout<< d[j] << ‘ ‘;


cout << endl;

return 0;


}

 

Generic bubble sort with Output

Generic Bubble sort in C
Generic Bubble sort in C

END

C program to draw a square using graphics (clickHere)

A generic program for bubble sort

Note:- Maybe sometime above code doesn’t get user-friendly output, in codeblock ‘or’ any other EDITOR, All of C & C++ program tested in DOS compiler Turbo C.

Also Read

Types of functions in C    Read Here

I hope you will understand better if you study at M.U, in the exam of M.U you know how important this “C program Generic bubble sort in C. So please don’t forget to give your valuable feedback. Go in the comment section and Give us some feedback about it. C program to generic bubble sort in C or My website.

Our team check your every Comment per day Because your one feedback helps us in growing Thesmolt

Generic bubble sort C

I request you if you have any doubt or question regarding our site, then please don’t hesitate. We always waiting for your Suggestion.

Note:- If you want to Download This article’s in PDF form, then simply go (Top or Bottom of) Right corner and click on the PRINT icon, and it’s saved as a PDF of C program to Generic bubble sort in C

 

For further questions, you can contact us Via mail [email protected]  otherwise, Our Help Page and Contact us Page, which is included below. I hope I’ll able to say all the possible ways to reach us. Or Download My Android Application Below Download Button.

thesmolt App

Leave a Reply

x