So recent, I started to learn linked list in class and I am confused. She did a whole explanation and some examples, but it doesn't make sense. So for example I have a header file for the class Node and class AnyList.
I have a few functions that I need to implement, but it's a bit difficult for me. One of my functions is suppose to delete the last node of the list.
#ifndef ANYLIST_H
#define ANYLIST_H
#include<iostream>
#include <string>
usingnamespace std;
class Node
{
public:
Node() { next = nullptr; }
Node(const string& theData, Node *nextNode) : data(theData), next(nextNode){}
Node* getNext( ) const { return next; }
string getData( ) const { return data; }
void setData(const string& theData) { data = theData; }
void setNext(Node *nextNode) { next = nextNode; }
~Node(){}
private:
string data;
Node *next; //pointer that points to next node
};
class AnyList
{
public:
AnyList();
void insertBack(const string& newData);
void print() const;
void destroyList();
~AnyList();
/*************************************************************************/
// Declaration of function getFirstElement
Node getFirstElement() const;
// Declaration of function deleteFirstNode
string deleteFirstNode(const AnyList& list);
// Declaration of function deleteLastNode
string deleteLastNode(const AnyList& list) const;
// Declaration of function replaceData
string replaceData(const AnyList& list) const;
private:
Node *first; //pointer to point to the first node in the list
int numOfItems; //keeps track of number of nodes in the list
};
#endif
Yep, that's the way, and thanks because it means you get more people looking at your problem and offering assistance. The 'pink slip' wasn't mine, but it's really frustrating with multiple posts on exactly the same problem.
Cheers :)