Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- void insertionSort(vector<double> &data)
- {
- for (int j = 1; j < data.size(); j++)
- {
- double key = data.at(j);
- int i = j - 1;
- while (i >= 0 && data.at(i) > key)
- {
- data.at(i+1) = data.at(i);
- i--;
- }
- data.at(i+1) = key;
- }
- }
- int main(){
- ifstream inputFile("input.txt");
- double inputValue;
- vector<double> data;
- cout << "Data:" << endl;
- while (inputFile >> inputValue)
- {
- data.insert(data.begin(), inputValue);
- cout << inputValue << " ";
- } // input
- cout << endl;
- insertionSort(data);
- cout << "Sorted data:" << endl;
- for (auto c : data)
- {
- cout << c << " ";
- } //output
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement