Hej! Piszę na zajęcia bibliotekę mającą umożliwiać operacje na dowolnie dużych liczbach (dodawanie i odejmowanie). Pomysł z jakiego chcę skorzystać to aby w operatorze liczby były odwracane(np 1023 do 3201), a następnie tworzona pomocnicza struktura "liczba" będąca po prostu przeniesieniami z dodawania pod kreską. Funkcję która odwraca kolejkę liczb już mam, problem pojawia się gdy chcę ją wywołać w operatorze dodawania. Nie chce się to za nic skompilować. W jaki sposób mogę użyć funkcji rev() w operatorze dodawania?
#ifndef QUEUE_H
#define QUEUE_H
#include <iostream>
#include <stdexcept>
using namespace std;
class Queue
{
class Node
{
public:
char cont;
Node* next;
Node* pred;
Node(char c, Node* n = nullptr, Node* p = nullptr)
{
cont = c;
next = n;
pred = p;
}
};
Node* head = nullptr;
Node* tail = nullptr;
int howBig = 0;
public:
Queue() = default;
~Queue()
{
if(howBig == 0)
cout << "Structure is empty." << endl;
else
{
Node* killer;
while(head != nullptr)
{
killer = head;
head = head->next;
delete killer;
howBig--;
}
cout << "Structure deleted. " << endl;
}
}
void show()
{
if(howBig == 0)
throw logic_error("The structure is empty!");
else
{
Node* runner = head;
while(runner != nullptr)
{
cout << runner->cont;
runner = runner-> next;
}
}
}
void add(char a)
{
Node* _new = new Node(a);
if(head == nullptr)
{
head = _new;
tail = _new;
}
else
{
tail->next = _new;
tail = tail->next;
}
howBig++;
}
void addToBeginning(char a)
{
Node* _new = new Node(a);
if(head == nullptr)
{
head = _new;
tail = _new;
}
else
{
_new->next = head;
head = _new;
}
howBig++;
}
void rev()
{
if(howBig == 0)
throw logic_error("Structure is empty!");
else
{
int i = 0;
Node* firsthead = head;
Node* pom = firsthead->next;
while(firsthead->next!=nullptr)
{
firsthead->next = firsthead->next->next;
pom->next = head;
head = pom;
pom = firsthead->next;
}
}
}
Queue operator+ (const Queue &q) const
{
q.rev();
this.rev();
}
//Queue operator- (const Queue &q) const;
};
#endif // QUEUE_H