answersLogoWhite

0

Bubblesort in c plus plus enter number?

Updated: 8/18/2019
User Avatar

Wiki User

9y ago

Best Answer

Optimised bubble-sort algorithm for use with small vectors of any type:

template<typename T>

void bubble_sort(std::vector<T>& v)

{

unsigned size = v.size();

if (1<size)

{

do

{

int n = 0;

for(int i=1; i<size; ++i)

{

if (v[i]<v[i-1])

{

std::swap (v[i-1], v[i]);

n=i;

}

}

size=n;

}

while (size);

}

}

Note that an insert sort is more efficient for small subsets, but std::sort handles subsets of any size extremely efficiently using a hybrid sorting algorithm.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Bubblesort in c plus plus enter number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

C plus plus code that determine prime number?

#include &lt;iostream.h&gt; main() { int a; cout&lt;&lt;"enter a number : "; cin&gt;&gt;a; cout&lt;&lt;endl; if (a%2-1) cout&lt;&lt;"it is a prime number"; else cout&lt;&lt;"it is not a prime number" return 0; } ------------------------------------------ output: enter a number : 30 it is a not a prime number


How do you enter a sentence as input in c plus plus?

Use the C++ getline() function from the standard library.


What is the C plus plus plus program for the addition of two numbers?

#include&lt;iostream&gt; int main() { int num1, num2; std::cout &lt;&lt; "C++ addition program" &lt;&lt; std::endl; std::cout &lt;&lt; "Enter a number: "; std::cin &gt;&gt; num1; std::cout &lt;&lt; "Enter another number: "; std::cin &gt;&gt; num2; std::cout &lt;&lt; "The sum is " &lt;&lt; num1 + num2 &lt;&lt; std::endl; }


What is the value of a b and c in the equation ax2 plus bx plus c?

any number


How do you create a add program in c plus plus?

#include &lt;iostream&gt; int main() { int num1=0, num2=0; printf( "Enter a number: " ); scanf_s( "%d", num1 ); printf( "Enter another number: " ); scanf_s( "%d", num2 ); printf( "Total is: %d\n", num1 + num2 ); return( 0 ); }


Write a program that will prompt you to give the number of pods and the number of beans per pod and calculate the total number of beans use C plus plus?

#includeusing namespace std;int main(){int pods,beans;float total;cout>beans;total=pods+beans;cout


C plus plus program to print number patterns?

bghjg


Even or odd in c plus plus program?

#include &lt;iostream&gt; int main() { int num; std::cout &lt;&lt; "Enter a number: "; std::cin &gt;&gt; num; if(num % 2 == 0) { std::cout &lt;&lt; "Number is even"; } else { std::cout &lt;&lt; "Number is odd"; } return 0; }


How do you find the greatest of three numbers using vb script?

dim a,b,c a=cint(inputbox("enter value for a")) b=cint(inputbox("enter value for b")) c=cint(inputbox("enter value for c")) if((a&gt;b)and(a&gt;c)) then msgbox "greatest number is a="&amp;a else if ((b&gt;a)and(b&gt;c)) then msgbox "greatest number is b="&amp;b else msgbox "greatest number is c="&amp;c end if end if


How you can use two input in a single statement in c plus plus?

cout&lt;&lt;"______": cin &gt;&gt;__&gt;&gt;__; [example cout&lt;&lt;"enter no."; cin&gt;&gt;a&gt;&gt;b; ]


Can be there number of catch and try block in c plus plus programs?

Yes.


What is the Aram strong number in c plus plus?

If the sum of squares of digits of a number equals to the number itself, then that number is called an aram strong number.