Facebook
From Eryk Bartosik, 4 Years ago, written in C#.
This paste is a reply to Przed Instrumentacją from Eryk Bartosik - view diff
Embed
Download Paste or View Raw
Hits: 433
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. namespace Projekt1
  5. {
  6.  
  7.     class Program
  8.     {  
  9.         static void Main(string[] args)
  10.         {
  11.             int a = 0;
  12.             int[] array = new int [268435456];
  13.             for(int i = 0; i < array.Length; i++)
  14.             {
  15.                array[i] = a; //przypisanie wartości do tablicy array
  16.                a++;
  17.             }
  18.  
  19.             int x = 1;
  20.  
  21.             int h = 0;                 //wyszukiwanie liniowe
  22.             bool warunek2 = true;
  23.             while(warunek2 == true)
  24.             {
  25.                 if(h < array.Length)
  26.                 {
  27.                  if(array[h] == x)
  28.                  {
  29.                      Console.WriteLine("Liniowe: Szukany element znajduje się pod inteksem "+h);
  30.                      warunek2 = false;
  31.                  }
  32.                 else
  33.                  {
  34.                      h++;
  35.                  }
  36.                 }
  37.                 else
  38.                 {
  39.                     Console.WriteLine("Liniowe: Nie znaleziono szukanego elementu");
  40.                     warunek2 = false;
  41.                 }
  42.             }
  43.  
  44.             Console.WriteLine();
  45.             Console.WriteLine();
  46.             Console.WriteLine();
  47.  
  48.             //sort(array);
  49.             int l = 0;                                         //wyszukiwnaie binarne
  50.             int p = array.Length;
  51.             bool warunek = true;
  52.             while(warunek == true)
  53.             {
  54.                 if(l<p)
  55.                 {
  56.                 int s = (l+p)/2;
  57.                 if(array[s] == x)
  58.                 {
  59.                     Console.WriteLine("Binarne: Szukany element znajduje się pod inteksem "+s);
  60.                     warunek = false;
  61.                 }
  62.                 else
  63.                 {
  64.                     if(array[s]<x)
  65.                     {
  66.                         l = s + 1;
  67.                     }
  68.                     else
  69.                     {
  70.                         p = s - 1;
  71.                     }
  72.                 }
  73.                 }
  74.                 else
  75.                 {
  76.                     Console.WriteLine("Binarne: Nie można odnaleźć szukanego elementu.");
  77.                     warunek = false;
  78.                 }
  79.         }
  80.     }
  81. }
  82. }

Replies to Re: Przed Instrumentacją rss

Title Name Language When
Re: Re: Przed Instrumentacją Eryk Bartosik csharp 4 Years ago.