Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SORTING_ARRAY_by_choice_.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- #include<iomanip>
- using namespace std;
- void unos(int[], int);
- void sortiranje(int[], int,int);
- void ispis(int[], int);
- int main()
- {
- int niz[10], izbor;
- unos(niz, 10);
- do {
- cout << "U kom poretku zelite sortirati dati niz ? Za opadajuci (1), za rastuci (2)" << endl;
- cin >> izbor;
- } while (izbor != 1 && izbor != 2);
- sortiranje(niz, 10, izbor);
- ispis(niz, 10);
- system("pause>0");
- return 0;
- }
- void unos(int niz[], int vel)
- {
- for (int i = 0; i < vel; i++)
- {
- cin >> niz[i];
- }
- }
- void sortiranje(int niz[], int vel, int izbor)
- {
- bool promena = true;
- int temp;
- while (promena)
- {
- promena = false;
- for (int i = 0; i < vel - 1; i++)
- {
- if (niz[i]<niz[i + 1] && izbor == 1 || niz[i]>niz[i + 1] && izbor == 2)
- {
- temp = niz[i];
- niz[i] = niz[i + 1];
- niz[i + 1] = temp;
- promena = true;
- }
- }
- }
- }
- void ispis(int niz[], int vel)
- {
- for (int i = 0; i < vel; i++)
- {
- cout << niz[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement