Program C ++ Doubly Linked List
Od kilku miesięcy próbuję nauczyć się programowania, kupiłem około trzech książek i obejrzałem tonę filmów na YouTube, która do tej pory była świetna. Ale w zeszłym tygodniu miałem problemy z połączonymi listami! Mam całą koncepcję, ale składnia mnie zabija! Napisałem kilka bardzo prostych programów z listami połączonymi do ćwiczeń, ale teraz próbuję napisać program, w którym ładuję niektóre informacje z pliku (informacje o osobach, które złożyły wniosek o wizę) na połączoną listę, a potem tylko wyświetl całą zawartość (raz to zrobię, planuję rozszerzyć ją do miejsca, w którym wyświetlaję tylko niektóre węzły i usuwam pewne węzły, ale nie będę wchodził w szczegóły). Mam nadzieję, że pokazany poniżej kod nie jest zbyt długi, a jeśli mógłbym po prostu zdobyć jakieś wskaźniki (bez gry słów) lub fragmenty, które pomogą mi zrozumieć te rzeczy, które byłyby niesamowite!
p.s część tego kodu pochodzi z podobnego przykładu w książce.
tutaj jest główna (większość) z pętlą do załadowania informacji (nie działa)
List myList;
visa_application *visa;
Node * pNode;
string visa_type;//these are all the variables that i want to load from the file
int invoice_no;
string surname;
string firstname;
double contact;
string status;
string result;
ifstream in;
in.open("applications.txt",ios::in);
while (!in.eof()){
pNode = new Node;
visa = new visa_application; //allocate memory for nodes
in >> visa-> visa_type >> visa->invoice_no >> visa-> surname;
in >> visa-> firstname >> visa-> contact >> visa-> status >> visa-> result ;
pNode->nData = &visa; //put some data in the node
myList.appendNode(pNode); //add node to list
}
Oto mój plik nagłówkowy klasy węzła
class Node
{
friend class List;
private:
node_data * nData;
Node *pNext;
Node *pPrev;
public:
Node (node_data * data){nData = data;
pNext = NULL;
pPrev = NULL;}
node_data * getData(){return nData;}
};
tutaj znajduje się plik nagłówkowy listy klas
class List
{
private:
Node *pHead;
Node *pTail;
Node *createNode(node_data * data);
public:
List ();
~List();
Node *getpHead (){ return pHead;}
Node *getpTail (){return pTail;}
Node *previousNode(Node *pNode){return pNode->pPrev;}
Node *nextNode (Node *pNode){return pNode->pNext;}
void appendNode(node_data * value);
void insertNode(node_data * value, Node *pAfter);
void removeNode(Node *pNode);
bool isEmpty();
void printList();
};
List ::List() {
pHead=NULL;
pTail=NULL;
}
List ::~List(){
while (!isEmpty()) //keep on removing until the
//head points to NULL
removeNode(pHead);
cout << "List deleted\n";
}
Node * List::createNode(node_data * data){
Node * pNode = new Node (data); //allocate memory for new node and
//intialize value to data
return pNode;
}
bool List ::isEmpty(){
return pHead == NULL;
}
void List ::appendNode(node_data * value)
{
Node * pNode = createNode(value);
if (isEmpty()) { //if list is empty
pHead = pNode; //make head point to pNode
pNode->pPrev = NULL;
}
else { //otherwise
pTail->pNext = pNode; //make tail point to pNode
pNode->pPrev = pTail;
}
pTail = pNode; //tail is now pNode
pNode->pNext = NULL; //pNode next now points to NULL
}
void List ::insertNode(node_data * value, Node *pAfter)
{
Node *pNode = createNode(value);
pNode->pNext = pAfter->pNext;
pNode->pPrev = pAfter;
if (pAfter->pNext != NULL)
pAfter->pNext->pPrev = pNode;
else
pTail = pNode;
pAfter->pNext = pNode;
}
void List ::removeNode(Node *pNode)
{
if (pNode->pPrev == NULL) //if removing the head
pHead = pNode->pNext;
else
pNode->pPrev->pNext = pNode->pNext; //if removing a middle node
if (pNode->pNext == NULL) //if removing the tail
pTail = pNode->pPrev;
else
pNode->pNext->pPrev = pNode->pPrev;
pNode = NULL;
delete pNode; //*free the memory
}
void List ::printList()
{
Node *pNode=pHead;
if (isEmpty())
cout << "The list is empty\n";
else
for (pNode = pHead; pNode != NULL; pNode = pNode->pNext)
pNode->nData->print();
}
Mój plik nagłówkowy aplikacji wizowej klasy
class visa_application
{
public:
// class constructor
visa_application();
// class destructor
~visa_application();
private:
string visa_type;
int invoice_no;
string surname;
string firstname;
double contact;
string status;
string result;
};
i wreszcie wiza application.cpp
visa_application::visa_application()
{
string visa_type = none;
int invoice_no = 0;
string surname = none;
string firstname = none;
double contact = 00;
string status = none;
string result = none;
}
class destructor
visa_application::~visa_application()
{
// insert your code here
}
Dostaję błąd „brak pasującej funkcji do wywołania` List :: appendNode (węzeł * i) '”wśród kilku innych rzeczy. Wiem, że to jest długie, ale byłoby wspaniale, gdybym mógł uzyskać pomoc, I nie miej nauczyciela ani nauczyciela, ani kogoś takiego, kto by mi pomógł, więc wszelkie opinie będą bardzo mile widziane! Dzięki!
** EDIT komunikaty o błędach to:
no matching function for call to `Node::Node()'
candidates are: Node::Node(const Node&)
Node::Node(node_data*)
no matching function for call to `List::appendNode(Node*&)'
candidates are: void List::appendNode(node_data*)