Bubble Sort :-
- #include "stdafx.h" // header file for MS VS
- #include <conio.h> // header file
- #include <iostream> // some compiler used <iostream.h>
- using namespace std ;
- int main()
- {
- int a[15] = {1,6,9,7,8,11,4,3,2,5,14,15,13,10,12} ; // Unsorted list
- // Process of sorting the list (Bubble sort)
- int index = 0 ;
- while ( index < 14 )
- {
- for (int i = 0 ; i < 14 ; i++ )
- {
- if (a[i] > a[i + 1])
- {
- int m = a[i] ;
- a[i] = a[i + 1] ;
- a[i + 1] = m ;
- }
- }
- index ++ ;
- }
- // For printing the sorted list
- for (int i = 0 ; i < 15 ; i ++)
- cout << a[i]<< "," ;
- _getch() ; // Some compiler use getch()
- return 0;
- }
0 comments:
Post a Comment