C++ Interrupted Bubble Sort I've written an interrupted bubble sort, which prints the intermediate result after some specified number of iterations of bubble sort. But I seem to have an speed issue. Could anyone help me spot some places that need to be optimized or are just plain wrong?

#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;sstream&gt;

using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::ifstream;
using std::stoi;
using std::stringstream;

template&lt;typename T&gt;
void printVector(vector&lt;T&gt; vect) {
    for(int i = 0; i &lt; vect.size(); i++) {
        if(i == 0) {
            cout &lt;&lt; vect[i];
        } else {
            cout &lt;&lt; " " &lt;&lt; vect[i];
        }
    }
    cout &lt;&lt; endl;
}

template&lt;typename T&gt;
void swap(T &amp;elementOne, T &amp;elementTwo) {
    T temp = elementOne;
    elementOne = elementTwo;
    elementTwo = temp;
}

void bubbleSort(vector&lt;int&gt; numbers, long int iterations) {
    for(int i = 0; i &lt; iterations; i++) {
        for(int j = 0; j &lt; numbers.size(); j++) {
            if(numbers[j] &gt; numbers[j + 1]) {
                swap(numbers[j], numbers[j + 1]);
            }
        }
    }
    printVector(numbers);
}

void parse(string line) {
    size_t delimiterPos = line.find("|");
    long int iterations = stol(line.substr(delimiterPos + 1));
    string numbersString = line.substr(0, delimiterPos - 1);

    stringstream numbersSS(numbersString);
    vector&lt;int&gt; numbers;
    int tempNum;
    while(numbersSS &gt;&gt; tempNum) {
        numbers.push_back(tempNum);
    }
    bubbleSort(numbers, iterations);
}

int main(int argc, const char * argv[]) {
    ifstream file(argv[1]);
    string line;
    while(getline(file, line)) {
        parse(line);
    }
    return 0;
}
Single Responsibility

As written, parse parses data and sorts them. This is plain wrong. Same goes for bubbleSort which sorts and prints. I recommend to change parse to

long int parse(string line, vector&lt;int&gt;&amp; numbers);


and use it as in

vector&lt;int&gt; data;
while (getline(file, line)) {
    long int iterations = parse(line, data);
    bubbleSort(data, iterations);
    printVector(data);
}

Kudos for not using namespace std!
The code seems to implement interrupted bubble sort correctly. I don't really understand the expected outcome of the assignment so no comments on the speed.