Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Project_1
- {
- class Program
- {
- public static int[] array = { 3, 1, 5, 2, 4 };
- public delegate void bubbleS(int[] a);
- static void Main(string[] args)
- {
- bubbleS sortA = new bubbleS(BubbleSortAsc);
- bubbleS sortB = new bubbleS(BubbleSortDesc);
- sortA(array);
- sortB(array);
- Console.ReadLine();
- }
- public static void BubbleSortAsc(int[] array)
- {
- int temp;
- for (int counter = 0; counter < array.Length; counter++)
- {
- for (int index = 0; index < array.Length - 1 - counter; index++)
- {
- if (array[index] > array[index + 1])
- {
- temp = array[index];
- array[index] = array[index + 1];
- array[index + 1] = temp;
- }
- }
- }
- for (int i = 0; i < array.Length; i++)
- {
- Console.WriteLine(array[i]);
- }
- }
- public static void BubbleSortDesc(int[] array)
- {
- int temp;
- for (int counter = 0; counter < array.Length; counter++)
- {
- for (int index = 0; index < array.Length - 1 - counter; index++)
- {
- if (array[index] < array[index + 1])
- {
- temp = array[index];
- array[index] = array[index + 1];
- array[index + 1] = temp;
- }
- }
- }
- for (int i = 0; i < array.Length; i++)
- {
- Console.WriteLine(array[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement