Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //int[] tomb = new int[3] { 1, 2, 3 }; // 0 csere
- //int[] tomb = new int[3] { 3, 2, 1 }; // 1 csere
- //int[] tomb = new int[3] { 2, 3, 1 }; // 2 csere
- //int[] tomb = new int[4] { 2, 4, 3, 1 }; // 2 csere
- //int[] tomb = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // 0 csere
- //int[] tomb = new int[10] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; // 5 csere
- //int[] tomb = new int[10] { 1, 2, 3, 4, 5, 6, 7, 9, 8, 10 }; // 1 csere
- //int[] tomb = new int[10] { 1, 7, 10, 3, 2, 8, 4, 9, 6, 5 }; // 7 csere
- int[] tomb = new int[10] { 7, 10, 1, 3, 2, 8, 4, 9, 6, 5 }; // 7 csere
- int csere = 0;
- for (int i = 0; i < tomb.Length; i++) {
- Console.Write(tomb[i]+" ");
- }
- for (int i = 0; i < tomb.Length; i++) {
- if (tomb[i] != i+1) {
- int j = i;
- int tmp = tomb[j];
- tomb[i] = i+1;
- do {
- j++;
- if (tomb[j] == i+1) { break; }
- } while (true);
- tomb[j] = tmp;
- csere++;
- }
- }
- Console.WriteLine("\nCserek szama: " + csere );
- for (int i = 0; i < tomb.Length; i++){
- Console.Write(tomb[i] + " ");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement