Habsburg

2.

May 25th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void BubbleSort(int polje[], int N) {
  5.     bool found = true;
  6.     while(found) {
  7.         found = false;
  8.         for(int i = 0; i < N - 1; i++)
  9.             if(polje[i] > polje[i+1]) {
  10.                 swap(polje[i], polje[i+1]);
  11.                 found = true;
  12.             }
  13.     }
  14. }
  15.  
  16. void najmanj(int polje[], int N) {
  17.     int i = 0;
  18.     cout << "i: ";
  19.     cin >> i;
  20.     if(i > N)
  21.         return;
  22.     cout << polje[i - 1] << endl;
  23. }
  24.  
  25. int main() {
  26.     int N;
  27.     do {
  28.         cout << "N: ";
  29.         cin >> N;
  30.     }while(N < 0);
  31.     int polje[N];
  32.     for(int i = 0; i < N; i++) {
  33.         cout << i+1 << ": ";
  34.         cin >> polje[i];
  35.     }
  36.     BubbleSort(polje,N);
  37.     najmanj(polje,N);
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment