Facebook
From C#, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 206
  1.     using System;
  2.     using System.Collections.Generic;
  3.     using System.Linq;
  4.     using System.Text;
  5.     using System.Threading.Tasks;
  6.  
  7.     namespace ConsoleApp18
  8.     {
  9.  
  10.  
  11.     class Kolejka
  12.         {
  13.             int[] tablica = new int[0];
  14.             int ile = 0;
  15.  
  16.             public void Push(int x)
  17.             {
  18.             int[] nowa = new int[ile + 1];
  19.             for (int i = 0; i < ile; i++) nowa[i] = tablica[i];
  20.             nowa[ile] = x;
  21.             tablica = nowa;
  22.             ile++;  
  23.             }
  24.  
  25.             public void Pop()
  26.             {
  27.                 int a = tablica[0];
  28.                 int[] temp = new int[ile - 1];
  29.                 for (int i = 1; i < ile; i++) temp[i - 1] = tablica[i];
  30.                 ile--;
  31.                 tablica = temp;
  32.             }
  33.  
  34.             public void Show()
  35.             {
  36.             for (int i = 0; i < ile; i++) Console.WriteLine(tablica[i]);
  37.             }
  38.  
  39.             public void dlugosc()
  40.             {
  41.                 Console.WriteLine("kolejka jest dlugosci: "+ ile);
  42.             }
  43.     }
  44.  
  45.  
  46.         class Stos
  47.         {
  48.         int[] tablica = new int[0];
  49.         int ile = 0;
  50.             public void Push(int x)
  51.             {
  52.                 int[] nowa = new int[ile + 1];
  53.                 for (int i = 0; i < ile; i++) nowa[i] = tablica[i];
  54.                 nowa[ile] = x;
  55.                 tablica = nowa;
  56.                 ile++;
  57.             }
  58.  
  59.             public void Pop(int x)
  60.             {
  61.                 int[] nowa = new int[ile-1];
  62.                 for (int i = 0; i < ile-1; i++) nowa[i] = tablica[i];
  63.                 tablica = nowa;
  64.                 ile--;
  65.             }
  66.  
  67.             public void Show()
  68.             {
  69.                 for (int i = 0; i < ile; i++) Console.WriteLine(tablica[i]);
  70.             }
  71.  
  72.             public void dlugosc()
  73.             {
  74.                 Console.WriteLine("Stos jest dlugosci: " + ile);
  75.             }
  76.         }
  77.  
  78.     class Program
  79.         {
  80.             static void Main(string[] args)
  81.             {
  82.             Kolejka kolejka = new Kolejka();
  83.             kolejka.Push(5);
  84.             kolejka.Push(3);
  85.             kolejka.Push(4);
  86.             kolejka.Push(1);
  87.             kolejka.Pop();
  88.             kolejka.Show();
  89.  
  90.  
  91.                 Console.ReadKey();
  92.             }
  93.         }
  94.     }
  95.