Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- int n = 10;
- int tab[10];
- int pom = 0;
- cout << "Wprowadz znaki po enterze" << endl;
- for (int i = 0; i < 10; i++) {
- cin >> tab[i];
- }
- for (int i = 0; i < n; i++)
- {
- cout << tab[i] << " ";
- }
- cout << endl << endl;
- for (int i = 1; i < n; i++)
- {
- pom = i - 1;
- for (int j = i; j < n; j++)
- {
- if (tab[j] < tab[pom])
- {
- pom = j;
- }
- }
- swap(tab[i - 1], tab[pom]);
- for (int i = 0; i < n; i++)
- {
- cout << tab[i] << " ";
- }
- cout << endl;
- }
- cout << endl;
- for (int i = 0; i < n; i++)
- {
- cout << tab[i] << " ";
- }
- cout << endl;
- }
- #include<iostream>
- using namespace std;
- void sort(int n, int* tab)
- {
- int pom, j;
- for (int i = 1; i < n; i++)
- {
- pom = tab[i];
- j = i - 1;
- while (j >= 0 && tab[j] > pom)
- {
- tab[j + 1] = tab[j];
- --j;
- }
- tab[j + 1] = pom;
- }
- }
- int main()
- {
- int n, * tab;
- cout << "Ilu elementowa tablica: ";
- cin >> n;
- tab = new int[n];
- cout << "wprowadz dane zatwierdz enterem:\n";
- for (int i = 0; i < n; i++)
- {
- cin >> tab[i];
- }
- sort(n, tab);
- for (int i = 0; i < n; i++)
- cout << tab[i] << " ";
- cin.ignore();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement