Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Element
- {
- public int wykladnik,wspolczynnik;
- public Element nastepny;
- public Element(int wspolczynnik, int wykladnik)
- {
- this.wspolczynnik = wspolczynnik;
- this.wykladnik = wykladnik;
- }
- public override string ToString()
- {
- return$"{wspolczynnik}, {wykladnik}";
- }
- public static Element operator +(Element e1, Element e2)
- {
- if (e1.wykladnik == e2.wykladnik) return new Element(e1.wspolczynnik + e2.wspolczynnik, e1.wykladnik);
- else return null;
- }
- public static Element operator -(Element e1, Element e2)
- {
- if (e1.wykladnik == e2.wykladnik) return new Element(e1.wspolczynnik - e2.wspolczynnik,e1.wykladnik);
- else return null;
- }
- }
- class Wielomian
- {
- Element head;
- public Wielomian(int[] tab )
- {
- if (tab.Length < 1) return;
- head = new Element(tab.Last(),tab.Length-1);
- Element e = head;
- for (int i = tab.Length-2; i >=0; --i)
- {
- if(tab [ i ]==0)continue;
- e.nastepny = new Element(tab[i],i);
- e = e.nastepny;
- }
- }
- public Wielomian()
- {
- head = null;
- }
- public void Rozniczkuj()
- {
- Element e = head;
- while (e != null)
- {
- e.wspolczynnik *= e.wykladnik;
- e.wykladnik--;
- if (e.nastepny.wykladnik == 0) e.nastepny = null;
- e = e.nastepny;
- }
- }
- public void WypisZ()
- {
- Element e = head;
- while (e != null)
- {
- Console.Write(e);
- if(e.nastepny != null) Console.Write("->");
- e = e.nastepny;
- }
- Console.WriteLine();
- }
- }
Add Comment
Please, Sign In to add comment