Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <stdio.h>
- using namespace std;
- void bubbleSort(vector<int>& a)
- {
- bool swapp = true;
- while(swapp)
- {
- swapp = false;
- for (int i = 0; i < a.size()-1; i++)
- {
- if (a[i]>a[i+1] )
- {
- a[i] += a[i+1];
- a[i+1] = a[i] - a[i+1];
- a[i] -=a[i+1];
- swapp = true;
- }
- }
- }
- }
- void printArray(vector<int> a){
- cout << "\n Sortirano polje: \n";
- for (size_t i=0; i <a.size(); i++) {
- cout<<a[i]<<" ";
- }
- cout<<endl;
- }
- int main()
- {
- vector<int> polje;
- ifstream inputFile("niz.txt");
- if (inputFile.good()) {
- int current_number = 0;
- while (inputFile >> current_number){
- polje.push_back(current_number);
- }
- inputFile.close();
- }else {
- cout << "Error!";
- _exit(0);
- }
- cout << "Ucitano polje: \n";
- printArray(polje);
- bubbleSort(polje);
- printArray(polje);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement