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 ushtrime1243
- {
- class Program
- {
- static void Main(string[]args )
- {
- int[] vargu = { 10, 8, 4, 12, 16, 3, 7, 2 };
- Console.WriteLine("Vargu para Sortimit");
- ParaqiteVargun(vargu);
- Console.WriteLine("Vargu i sortuar");
- //SortiBubble(vargu);
- //SortiSelektiv(vargu
- SortiInsertim(vargu);
- Console.WriteLine("Kerkimi Binar");
- Console.WriteLine(KerkimiBinar(vargu,3));
- }
- public static void ParaqiteVargun(int[] vargu)
- {
- for (int i = 0; i < vargu.Length; i++)
- {
- Console.WriteLine(vargu[i] + "");
- }
- Console.WriteLine();
- }
- public static void SortiInsertim(int[]vargu)
- {
- int temp, j;
- for (int i = 1; i < vargu.Length; i++)
- {
- temp = vargu[i];
- for ( j=i-1; j>=0 && vargu[j] > temp; j--)
- {
- vargu[j + 1] = vargu[j];
- }
- vargu[j + 1] = temp;
- ParaqiteVargun(vargu);
- }
- }
- public static int KerkimiBinar(int[] vargu,int vlera)
- {
- int kufiriPoshtem = 0;
- int kufiriSiperm = vargu.Length;
- int messi;
- while (kufiriPoshtem<=kufiriSiperm)
- {
- messi = (kufiriPoshtem + kufiriSiperm) / 2;
- if (vargu[messi] == vlera)
- return messi;
- else if (vlera > vargu[messi])
- kufiriPoshtem = messi + 1;
- else
- kufiriSiperm = messi - 1;
- }
- return -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement