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 ConsoleApplication28
- {
- class Pole<T>
- {
- private List<T> list;
- public int Kapacita { get; private set; }
- public Pole(int kapacita)
- {
- Kapacita = kapacita;
- list = new List<T>(Kapacita);
- }
- public void InsertAt(int index, T hodnota)
- {
- list.Insert(index, hodnota);
- Vypis();
- }
- public void Vypis()
- {
- Console.WriteLine(string.Join(",", list));
- }
- }
- class Pole2<T>
- {
- private T[] data;
- public int Kapacita { get; private set; }
- public Pole2(int kapacita)
- {
- Kapacita = kapacita;
- data = new T[Kapacita];
- }
- public void InsertAt(int index, T hodnota)
- {
- for (int i = Kapacita - 1; i > index; i--)
- {
- data[i] = data[i - 1];
- }
- data[index] = hodnota;
- Vypis();
- }
- public void Vypis()
- {
- Console.WriteLine(string.Join(",", data));
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- // 1. s polem
- // 2. s listem
- Pole<int> p1 = new Pole<int>(4);
- p1.InsertAt(0, 1); // 1
- p1.InsertAt(0, 2); // 2 1
- p1.InsertAt(1, 3); // 2 3 1
- p1.InsertAt(2, 4); // 2 3 4 1
- Pole2<int> p2 = new Pole2<int>(4);
- p2.InsertAt(0, 1); // 1
- p2.InsertAt(0, 2); // 2 1
- p2.InsertAt(1, 3); // 2 3 1
- p2.InsertAt(2, 4); // 2 3 4 1
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement