Upcoming SlideShare
×

# Sorting Algorithms

543 views

Published on

Sorting Algorithms for Certificate in C/C++ Programming - ESOFT Metro Campus

Published in: Engineering
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

Views
Total views
543
On SlideShare
0
From Embeds
0
Number of Embeds
24
Actions
Shares
0
13
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Sorting Algorithms

1. 1. Sorting Algorithms Bubble Sort, Selection Sort and Insertion Sort Rasan Samarasinghe
2. 2. Bubble Sort
3. 3. Bubble Sort (C Implementation) int abc[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1 }; int c, i; for (c = 1; c <= 9; c++){ for (i = 0; i <= 7; i++){ if (abc[i] > abc[i + 1]){ int temp = abc[i]; abc[i] = abc[i + 1]; abc[i + 1] = temp; } } }
4. 4. Selection Sort
5. 5. Selection Sort (C Implementation) int abc[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1 }; int minindex, i, c; for (c = 0; c <= 8; c++){ minindex = c; for (i = c; i <= 8; i++){ if (abc[i] < abc[minindex]){ minindex = i; } } int temp = abc[c]; abc[c] = abc[minindex]; abc[minindex] = temp; }
6. 6. Insertion Sort
7. 7. Insertion Sort (C Implementation) int abc[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1 }; int c, i, index; for (c = 1; c <= 8; c++){ index = abc[c]; for (i = c; abc[i - 1] > index; i--){ abc[i] = abc[i - 1]; } abc[i] = index; }
8. 8. The End w: http://rasan.net e: rasansmn@gmail.com t: http://twitter.com/rasansmn