Linked list

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.

So this is the Header file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef ANYLIST_H
#define ANYLIST_H

#include<iostream>
#include <string>				
using namespace 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 



And this is the implement file (.cpp):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
	Randy Nguyen, Febuary 19 2017, Lab 4: More SLL
*/

#include "AnyList.h"
#include <string>


// Definition of function getFirstElement
Node AnyList::getFirstElement() const
{
	return *first;
}

// Definition of function deleteFirstNode
string AnyList::deleteFirstNode(const AnyList& list)
{

}

// Definition of function deleteLastNode
string AnyList::deleteLastNode(const AnyList& list) const
{

}

// Definition of function replaceData
string AnyList::replaceData(const AnyList& list) const
{

}
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/209043/
http://www.cplusplus.com/forum/general/209044/
http://www.cplusplus.com/forum/beginner/209050/
Last edited on
bump
closed account (48T7M4Gy)
Don't duplicate your posts. Close this thread down.
Is that how you close it?
closed account (48T7M4Gy)
Is that how you close it?

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 :)
Topic archived. No new replies allowed.