Lecture231 bubble quick pivot

Lecture231 bubble quick pivot - Bubble Sort...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 1 -- 1 Computer Science I - Martin Hardwick Bubble Sort int top) // Perform one bubble iteration on a list { bool   done = true;       int tmp; for (int k = 0; k < top - 1; k++) { if (list[k] > list[k + 1]) {      tmp = list[k+1];      list[k+1] = list[k];        list[k] = tmp;      done = false; } } return done; } This algorithm moves the largest item in the list to the top. Every time we run it the next biggest item moves to the top Consider 23 18 78 45 34 15 20 After bubble_once 18 23 45 34 15 20 78 After another 18 23 34 15 20 45 78 After another 18 23 15 20 34 45 78 If nothing moves we are done so we return true.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture 1 -- 2 Computer Science I - Martin Hardwick Bubble Sort Completed // Bubble sort a list { int     done = false;      int     top = list.size() ;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/30/2012 for the course CSCI 101 taught by Professor Hardwick during the Fall '08 term at Rensselaer Polytechnic Institute.

Page1 / 5

Lecture231 bubble quick pivot - Bubble Sort...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online