simple algorithm for bubble sort?

Answer Posted / siri

void bubble(int x[],int n)
{
int hold,j,pass;
int switched=true;
for(pass=0;pass<n-1&&switched=true;pass++){
switched=false;
for(j=0;j<n-pass-1;j++)
if(x[j]>x[j+1]){
switched=true;
hold=x[j];
x[j]=x[j+1];
x[j+1]=hold;
}
}
}

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do u mean by data type?

430


Define a priority queue?

592


How do you sort a collection in descending order?

539


Which sorting method is slowest?

529


Can we add elements to final list?

477






How to find 3rd element from end in a linked list in one pass?

459


How will you reverse Linked List.

528


Define a binary tree?

556


What is the Insertion Sort Code?.

627


Can we store a string and integer together in an array?

460


How can we reverse the order in the treemap?

482


Can hashset contain null?

467


What do you mean by separate chaining?

513


Does hashmap maintain insertion order?

493


How would you use bsearch() function to search a name stored in array of pointers to string?

484