Linked-List struct data type

How do I declare an instance of the linked list with the data type of a struct.
For example...

1
2
3
4
5
6
7
8
class DVD
{
private:
struct disc
{
int length;
string name;
};


And my linked list
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
template <class T>
class LinkedList1 
{
private:
// Declare a structure
struct discList
{
    T value;
    struct discList *next;  // To point to the next node
};

discList *head;     // List head pointer

public:
// Default Constructor
LinkedList1()
{ head = NULL; }


// Destructor
~LinkedList1();

// Linked list operations
void appendNode(T);
void insertNode(T);
void deleteNode(T);
void displayList() const;
};


Would it be LinkedList1<DVD> dvd;? That is only using the class as a data type for the linked list.. How do I use the struct disc as the data type?
Why do you define disc within the DVD?
My instructions are to have a class with a struct that holds the length of the dvd and the name. Here are my instructions which is the same for the DVD..
The CD class will use a linked list to keep track of the titles of the songs on the CD; this will allow each CD to have a different number of songs. It should also maintain the length of each song, thus the class will use a structure which will have the song title and its length. Each song will be an instance of this structure and will be stored in the linked list.
Last edited on
You've defined disc as private, so only code in the DVD class can use it. If you want the type to be usable by other code, e.g. the code that's creating the linked list, then you'll need to expose it in the public interface.
Last edited on
Thank you I will try that!
Topic archived. No new replies allowed.