Upload
saddam-hussain
View
210
Download
0
Tags:
Embed Size (px)
Citation preview
Sorting
Sorting takes an unordered collection and makes it an ordered one.
512354277 101
1 2 3 4 5 6
5 12 35 42 77 101
1 2 3 4 5 6
Introduction: Bubble Sort
Also called Exchange sort.It repeatedly visits the array and compares two items at a time. It swaps these two items if they are in the wrong order.It continues to visit the array until no swaps are needed thatmeans the array is sorted.
452314 33 42 676 98
We did not do any swapping,so all of the other elementsmust be correctly placed.
We can “skip” the last twopasses of the outer loop.
Program
void main(){ int arr[5],i,j,tem; cout<<“Enter Five Values”; for(i=0,i<5,i++) cin>>arr[i];
cout<<“The origanal values in array:\n”; for(i=0;i<5;i++) cout<<arr[i]<<“ “;