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 Zadanie_1a
- {
- class Wezel
- {
- public int a, p;
- public Wezel nastepny;
- }
- class Drzewo
- {
- public Wezel glowa;
- public void DodajElementy(int[] tab)
- {
- for (int i = 0; i < tab.Length; i++)
- {
- Wezel tmp = new Wezel();
- tmp.a = tab[i];
- tmp.p = i;
- tmp.nastepny = glowa;
- if (tab[i]!=0) glowa = tmp;
- }
- }
- public override string ToString()
- {
- string tmp = "";
- Wezel temp = glowa;
- while (temp!=null)
- {
- if (temp.p == 1) tmp += temp.a + "x + ";
- else if(temp.p != 0) tmp += temp.a + "x^" + temp.p + " + ";
- else tmp += temp.a + "";
- temp = temp.nastepny;
- }
- return tmp;
- }
- public void Rozniczkowanie()
- {
- Wezel tmp = glowa;
- while (tmp!=null)
- {
- if (tmp.p ==1) {
- tmp.a = tmp.a * tmp.p;
- tmp.p--;
- tmp.nastepny = tmp.nastepny.nastepny;
- tmp = tmp.nastepny;
- continue; }
- tmp.a =tmp.a* tmp.p;
- tmp.p--;
- tmp = tmp.nastepny;
- }
- }
- public void Dodawanie(Drzewo d)
- {
- Wezel tmp = glowa;
- Wezel dmp = d.glowa;
- while (tmp!=null)
- {
- tmp.a = tmp.a + dmp.a;
- tmp = tmp.nastepny; dmp = dmp.nastepny;
- }
- }
- public void Odejmowanie(Drzewo d)
- {
- Wezel tmp = glowa;
- Wezel dmp = d.glowa;
- while (tmp != null)
- {
- tmp.a = tmp.a - dmp.a;
- tmp = tmp.nastepny; dmp = dmp.nastepny;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Drzewo w = new Drzewo();
- int[] tablica = { 4, 10, 2, 5, 0, 0, 2 };
- w.DodajElementy(tablica);
- Console.WriteLine(w);
- w.Rozniczkowanie();
- Console.WriteLine(w);
- w.Dodawanie(w);
- Console.WriteLine(w);
- w.Odejmowanie(w);
- Console.WriteLine(w);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement