Top Banner
A Presentation topic for c++ topic A Good style and appreciated
82
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Bubble sort a best presentation topic

• A Presentation topic for c++ topic• A Good style and appreciated

Page 2: Bubble sort a best presentation topic

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

Page 3: Bubble sort a best presentation topic

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.

Page 4: Bubble sort a best presentation topic
Page 5: Bubble sort a best presentation topic
Page 6: Bubble sort a best presentation topic
Page 7: Bubble sort a best presentation topic
Page 8: Bubble sort a best presentation topic

674523 14 6 3398 42

The First “Bubble Up”

Page 9: Bubble sort a best presentation topic

674523 14 6 3398 42

The First “Bubble Up”

Page 10: Bubble sort a best presentation topic

674523 14 6 3398 42

Swap

The First “Bubble Up”

Page 11: Bubble sort a best presentation topic

674598 14 6 3323 42

Swap

The First “Bubble Up”

Page 12: Bubble sort a best presentation topic

674598 14 6 3323 42

The First “Bubble Up”

Page 13: Bubble sort a best presentation topic

674598 14 6 3323 42

Swap

The First “Bubble Up”

Page 14: Bubble sort a best presentation topic

679845 14 6 3323 42

Swap

The First “Bubble Up”

Page 15: Bubble sort a best presentation topic

679845 14 6 3323 42

The First “Bubble Up”

Page 16: Bubble sort a best presentation topic

679845 14 6 3323 42

Swap

The First “Bubble Up”

Page 17: Bubble sort a best presentation topic

671445 98 6 3323 42

Swap

The First “Bubble Up”

Page 18: Bubble sort a best presentation topic

671445 98 6 3323 42

The First “Bubble Up”

Page 19: Bubble sort a best presentation topic

671445 98 6 3323 42

Swap

The First “Bubble Up”

Page 20: Bubble sort a best presentation topic

671445 6 98 3323 42

Swap

The First “Bubble Up”

Page 21: Bubble sort a best presentation topic

671445 6 98 3323 42

The First “Bubble Up”

Page 22: Bubble sort a best presentation topic

671445 6 98 3323 42

Swap

The First “Bubble Up”

Page 23: Bubble sort a best presentation topic

981445 6 67 3323 42

Swap

The First “Bubble Up”

Page 24: Bubble sort a best presentation topic

981445 6 67 3323 42

The First “Bubble Up”

Page 25: Bubble sort a best presentation topic

981445 6 67 3323 42

Swap

The First “Bubble Up”

Page 26: Bubble sort a best presentation topic

331445 6 67 9823 42

Swap

The First “Bubble Up”

Page 27: Bubble sort a best presentation topic

331445 6 67 9823 42

The First “Bubble Up”

Page 28: Bubble sort a best presentation topic

331445 6 67 9823 42

Swap

The First “Bubble Up”

Page 29: Bubble sort a best presentation topic

331445 6 67 4223 98

Swap

The First “Bubble Up”

Page 30: Bubble sort a best presentation topic

331445 6 67 4223 98

Finished first “Bubble Up”

The First “Bubble Up”

Page 31: Bubble sort a best presentation topic

The Second “Bubble Up”

331445 6 67 4223 98

Page 32: Bubble sort a best presentation topic

The Second “Bubble Up”

331445 6 67 4223 98

No Swap

Page 33: Bubble sort a best presentation topic

The Second “Bubble Up”

331445 6 67 4223 98

Page 34: Bubble sort a best presentation topic

The Second “Bubble Up”

331445 6 67 4223 98

Swap

Page 35: Bubble sort a best presentation topic

The Second “Bubble Up”

334514 6 67 4223 98

Swap

Page 36: Bubble sort a best presentation topic

The Second “Bubble Up”

334514 6 67 4223 98

Page 37: Bubble sort a best presentation topic

The Second “Bubble Up”

334514 6 67 4223 98

Swap

Page 38: Bubble sort a best presentation topic

The Second “Bubble Up”

33614 45 67 4223 98

Swap

Page 39: Bubble sort a best presentation topic

The Second “Bubble Up”

33614 45 67 4223 98

Page 40: Bubble sort a best presentation topic

The Second “Bubble Up”

33614 45 67 4223 98

No Swap

Page 41: Bubble sort a best presentation topic

The Second “Bubble Up”

33614 45 67 4223 98

Page 42: Bubble sort a best presentation topic

The Second “Bubble Up”

33614 45 67 4223 98

Swap

Page 43: Bubble sort a best presentation topic

The Second “Bubble Up”

67614 45 33 4223 98

Swap

Page 44: Bubble sort a best presentation topic

The Second “Bubble Up”

67614 45 33 4223 98

Page 45: Bubble sort a best presentation topic

The Second “Bubble Up”

67614 45 33 4223 98

Swap

Page 46: Bubble sort a best presentation topic

The Second “Bubble Up”

42614 45 33 6723 98

Swap

Page 47: Bubble sort a best presentation topic

42614 45 33 6723 98

Finished second “Bubble Up”

The Second “Bubble Up”

Page 48: Bubble sort a best presentation topic

The Third “Bubble Up”

42614 45 33 6723 98

Page 49: Bubble sort a best presentation topic

The Third “Bubble Up”

42614 45 33 6723 98

Swap

Page 50: Bubble sort a best presentation topic

The Third “Bubble Up”

42623 45 33 6714 98

Swap

Page 51: Bubble sort a best presentation topic

The Third “Bubble Up”

42623 45 33 6714 98

Page 52: Bubble sort a best presentation topic

The Third “Bubble Up”

42623 45 33 6714 98

Swap

Page 53: Bubble sort a best presentation topic

The Third “Bubble Up”

42236 45 33 6714 98

Swap

Page 54: Bubble sort a best presentation topic

The Third “Bubble Up”

42236 45 33 6714 98

Page 55: Bubble sort a best presentation topic

The Third “Bubble Up”

42236 45 33 6714 98

No Swap

Page 56: Bubble sort a best presentation topic

The Third “Bubble Up”

42236 45 33 6714 98

Page 57: Bubble sort a best presentation topic

The Third “Bubble Up”

42236 45 33 6714 98

Swap

Page 58: Bubble sort a best presentation topic

The Third “Bubble Up”

42236 33 45 6714 98

Swap

Page 59: Bubble sort a best presentation topic

The Third “Bubble Up”

42236 33 45 6714 98

Page 60: Bubble sort a best presentation topic

The Third “Bubble Up”

42236 33 45 6714 98

Swap

Page 61: Bubble sort a best presentation topic

The Third “Bubble Up”

45236 33 42 6714 98

Swap

Page 62: Bubble sort a best presentation topic

After Third Pass of Outer Loop

45236 33 42 6714 98

Finished third “Bubble Up”

Page 63: Bubble sort a best presentation topic

The Fourth “Bubble Up”

45236 33 42 6714 98

Page 64: Bubble sort a best presentation topic

The Fourth “Bubble Up”

45236 33 42 6714 98

Swap

Page 65: Bubble sort a best presentation topic

The Fourth “Bubble Up”

452314 33 42 676 98

Swap

Page 66: Bubble sort a best presentation topic

The Fourth “Bubble Up”

452314 33 42 676 98

Page 67: Bubble sort a best presentation topic

The Fourth “Bubble Up”

452314 33 42 676 98

No Swap

Page 68: Bubble sort a best presentation topic

The Fourth “Bubble Up”

452314 33 42 676 98

Page 69: Bubble sort a best presentation topic

The Fourth “Bubble Up”

452314 33 42 676 98

No Swap

Page 70: Bubble sort a best presentation topic

The Fourth “Bubble Up”

452314 33 42 676 98

Page 71: Bubble sort a best presentation topic

The Fourth “Bubble Up”

452314 33 42 676 98

No Swap

Page 72: Bubble sort a best presentation topic

452314 33 42 676 98

Finished fourth “Bubble Up”

After Fourth Pass of Outer Loop

Page 73: Bubble sort a best presentation topic

The Fifth “Bubble Up”

452314 33 42 676 98

Page 74: Bubble sort a best presentation topic

The Fifth “Bubble Up”

452314 33 42 676 98

No Swap

Page 75: Bubble sort a best presentation topic

The Fifth “Bubble Up”

452314 33 42 676 98

Page 76: Bubble sort a best presentation topic

The Fifth “Bubble Up”

452314 33 42 676 98

No Swap

Page 77: Bubble sort a best presentation topic

The Fifth “Bubble Up”

452314 33 42 676 98

Page 78: Bubble sort a best presentation topic

The Fifth “Bubble Up”

452314 33 42 676 98

No Swap

Page 79: Bubble sort a best presentation topic

After Fifth Pass of Outer Loop

452314 33 42 676 98

Finished fifth “Bubble Up”

Page 80: Bubble sort a best presentation topic

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.

Page 81: Bubble sort a best presentation topic

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]<<“ “;

Page 82: Bubble sort a best presentation topic

for(i=0;i<5;i++) for(j=0;j<4;j++)If(arr[ j ]>arr[ j+1 ]{ tem=arr[ j ]; arr[ j ]=arr[ j+1 ]; arr[ j+1]=tem;} cout<<“\n The sorted array: \n”; for(i=0;i<5;i++) cout<<arr[ i ]<<“ “; getch();}