Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int binarySearch(const int [], int, int);
- void insertionSort(int*, int);
- int main()
- {
- int luck1, luck2, luck3, luck4, luck5;
- const int SIZE = 5;
- int winner[SIZE];
- cout << winner << endl;
- cout << "Mrs. Crockett, enter in your lucky numbers!\n";
- cout << "1: ";
- cin >> luck1;
- cout << "2: ";
- cin >> luck2;
- cout << "3: ";
- cin >> luck3;
- cout << "4: ";
- cin >> luck4;
- cout << "5: ";
- cin >> luck5;
- cout << "The winning lottery ticket number is: " << endl;
- }
- int binarySearch(const int array[], int size, int value)
- {
- int first = 0, // First array element
- last = size - 1, // Last array element
- middle, // Mid point of search
- position = -1; // Position of search value
- bool found = false; // Flag
- while (!found && first <= last)
- {
- middle = (first + last) / 2; // Calculate mid point
- if (array[middle] == value) // If value is found at mid
- {
- found = true;
- position = middle;
- }
- else if (array[middle] > value) // If value is in lower half
- last = middle - 1;
- else
- first = middle + 1; // If value is in upper half
- }
- return position;
- }
- void insertionSort(int *arr, int size)
- {
- int key; //key is the item that we are sorting at the moment
- int j; //j is the position of where key should be inserted into the sorted array
- cout << "\nSorting the array with the Insertion Sort algorithm.\n\n";
- //i will hold the subscript of the unsorted array
- for(int i=1; i < size; i++)
- {
- key = arr[i]; //select the item to be sorted
- j = i-1; //j is the element to the furthest right of the sorted array
- while(j >= 0 && arr[j] > key) //while we haven't gone out of bounds to the left of the array and the current element is still greater than key
- {
- arr[j+1] = arr[j]; //move elements to the right of the sorted array that are greater than the item (key)
- j = j-1; //decrement j
- }
- arr[j+1] = key; //place item in final sorted position
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement