Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. int main()
  2. {
  3.  
  4. int n = 10;
  5. int tab[10];
  6. int pom = 0;
  7. cout << "Wprowadz znaki po enterze" << endl;
  8.  
  9. for (int i = 0; i < 10; i++) {
  10. cin >> tab[i];
  11. }
  12.  
  13.  
  14.  
  15. for (int i = 0; i < n; i++)
  16. {
  17. cout << tab[i] << " ";
  18. }
  19. cout << endl << endl;
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26. for (int i = 1; i < n; i++)
  27. {
  28. pom = i - 1;
  29. for (int j = i; j < n; j++)
  30. {
  31. if (tab[j] < tab[pom])
  32. {
  33.  
  34. pom = j;
  35. }
  36. }
  37.  
  38. swap(tab[i - 1], tab[pom]);
  39.  
  40.  
  41.  
  42.  
  43.  
  44. for (int i = 0; i < n; i++)
  45. {
  46. cout << tab[i] << " ";
  47. }
  48. cout << endl;
  49. }
  50.  
  51. cout << endl;
  52. for (int i = 0; i < n; i++)
  53. {
  54. cout << tab[i] << " ";
  55. }
  56. cout << endl;
  57. }
  58. #include<iostream>
  59. using namespace std;
  60.  
  61. void sort(int n, int* tab)
  62. {
  63. int pom, j;
  64. for (int i = 1; i < n; i++)
  65. {
  66.  
  67. pom = tab[i];
  68. j = i - 1;
  69.  
  70.  
  71. while (j >= 0 && tab[j] > pom)
  72. {
  73. tab[j + 1] = tab[j];
  74. --j;
  75. }
  76. tab[j + 1] = pom;
  77. }
  78. }
  79.  
  80. int main()
  81. {
  82. int n, * tab;
  83. cout << "Ilu elementowa tablica: ";
  84. cin >> n;
  85.  
  86. tab = new int[n];
  87. cout << "wprowadz dane zatwierdz enterem:\n";
  88. for (int i = 0; i < n; i++)
  89. {
  90. cin >> tab[i];
  91. }
  92.  
  93.  
  94.  
  95. sort(n, tab);
  96.  
  97.  
  98. for (int i = 0; i < n; i++)
  99. cout << tab[i] << " ";
  100.  
  101. cin.ignore();
  102. cin.get();
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement