Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rextester.Program.Main is the entry point for your code. Don't change it.
- //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace Rextester
- {
- public class Program
- {
- public static void imprimirArray(int[] vetor) {
- for (int r = 0; r < vetor.Length; r++)
- {
- Console.Write("{0} ", vetor[r]);
- }
- }
- public static void pb(int[] vetor, int p , int u, int valor) {
- int l = 0;
- l = Convert.ToInt32((p+u)/2);
- if (valor == vetor[l]) {
- Console.WriteLine("{0} {1}", l, vetor[l]);
- } else {
- if (valor > vetor[l]) {
- p = l+1;
- pb(vetor, p, vetor.Length, valor);
- }
- else {
- u = l-1;
- pb(vetor, p, u, valor);
- }
- }
- }
- public static void Main(string[] args)
- {
- int[] vetor = new int[]{2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,48,50,52};
- //imprimirArray(vetor);
- int valor = 4;
- int posi;
- pb(vetor, 0, vetor.Length, valor);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment