|
||||||||||
copyright © 2006 Don Southwell - All rights reserved |
|
||||||||||
copyright © 2006 Don Southwell - All rights reserved |
Arrays Lab - Selection and Sorting Part A: Linear Selection Sort A lottery ticket buyer (not me) purchases 10 tickets a week, always playing the same 10, 5-digit "lucky" combinations. Write a program that initializes an array or a vector with these numbers and then lets the player enter this week's winning 5 digit number. The program should perform a linear search through the list of the player's numbers and report whether or not one of the tickets is a winner this week. Also output the number of comparisons required. Here are the numbers that are played each week:
Test Data:
Part B: Binary Search Modify the program you wrote for Part A (Lottery Winners) so it performs a binary search instead of a linear search. Also output the number of comparisons required. (Hint: You will need to sort the lottery numbers in preparation for using the binary search.) Part C: Sort Programs (Bubble and Selection) Write a program that uses two identical arrays of at least 20 integers. It should call a function that uses the bubble sort algorithm to sort one of the arrays in ascending order. The function should keep a count of the number of exchanges it makes. The program then should call a function that uses the selection sort algorithm to sort the other array. It should also keep count of the number of exchanges it makes. Display these values on the screen. Integers: 67, 90, 102, 4, 16, 32, 18, 23, 2, 112, 78, 43, 26, 13, 37, 22, 96, 82, 32 ,54 For Part A, B, and C - Turnin (in order, clearly labelled):
|
! You are using a version 4 browser or older. If you are experiencing any problems with scrolling, please reload the page.