Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace test1
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int[] array = { 1, 8, -6, 0, 5, 7, 7, 4, 101, 80, 6, -45, -8, -33, 100, -2, 3, 0, 1, 4, -6, 5, -8 };
- BubbleSort(array);
- Console.WriteLine(string.Join(" ", array));
- }
- private static void BubbleSort(int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- for (int j = 0; j < array.Length - 1 - i; j++)
- {
- if (array[j] > array[j + 1]) //ako treba u obrnutom poretku promeni se znak (> -> <)
- {
- Swap(array, j, j + 1);
- }
- }
- }
- }
- private static void Swap(int[] array, int i, int j)
- {
- int tmp = array[i];
- array[i] = array[j];
- array[j] = tmp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment