Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace lab4._2
- {
- public class Osoba
- {
- string imie;
- string nazwisko;
- public Osoba()
- {
- imie = "nieznane";
- nazwisko = "nieznane";
- }
- public Osoba(string imie_, string nazwisko_)
- {
- imie = imie_;
- nazwisko = nazwisko_;
- }
- public void WypiszInfo()
- {
- Console.WriteLine("Imię i nazwisko: " + imie + " " + nazwisko);
- }
- }
- public class Lista
- {
- private class Element
- {
- public Osoba wartosc;
- public Element nastepnyElement = null;
- public Element(Osoba o)
- {
- wartosc = o;
- }
- }
- Element pierwszyElement;
- int liczbaElementow = 0;
- public int LiczbaElementow
- {
- get => liczbaElementow;
- }
- public void Dodaj(Osoba wartosc)
- {
- var k = pierwszyElement;
- while(k != null)
- {
- k = k.nastepnyElement;
- }
- k = new Element(wartosc);
- liczbaElementow++;
- }
- public object Pobierz(int indeks)
- {
- if (indeks >= 0 && indeks < liczbaElementow)
- {
- object t = pierwszyElement.wartosc;
- pierwszyElement.wartosc = null;
- pierwszyElement = pierwszyElement.nastepnyElement;
- liczbaElementow--;
- return t;
- }
- else
- {
- Console.WriteLine("Brak elementów!");
- return null;
- }
- }
- /*public object Wstaw(Osoba o, int indeks)
- {
- if(indeks > 0 && indeks =< liczbaElementow)
- {
- }
- else
- {
- Console.WriteLine("Brak elementów!");
- return null;
- }
- }*/
- public void Wypisz()
- {
- var p = pierwszyElement;
- while (p != null)
- {
- p.wartosc.WypiszInfo();
- p = p.nastepnyElement;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Osoba o = new Osoba("Alicja", "Nowak");
- Osoba o2 = new Osoba("Karolina", "Kowalska");
- Osoba o3 = new Osoba("Michał", "Jabłoński");
- Osoba o4 = new Osoba("Karol", "Wiśniewski");
- Lista l = new Lista();
- l.Dodaj(o);
- l.Dodaj(o2);
- l.Dodaj(o3);
- l.Dodaj(o4);
- l.Wypisz();
- //l.Pobierz(2);
- //l.Pobierz(0);
- //l.Pobierz(1);
- l.Wypisz();
- //l.Wstaw(o3, 0);
- //l.Wstaw(o4, 1);
- //l.Wstaw(o, 2);
- l.Wypisz();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement