Errors :
||=== Build: Debug in ***(compiler: GNU GCC Compiler) ===|
main.cpp||In function 'int main()':|
error: 'template<class T> class DList' used without template parameters|
error: expected primary-expression before 'int'|
main.cpp|13|error: 'L' was not declared in this scope|
Code:
#ifndef DLish_h
#define DList_h
using namespace std;
// Define a template class DList for a doubly linked list
template < typename T >
class DList
{
public:
// Define a struct for the nodes in the list
struct Node
{
T data;
Node *next;
Node *prev;
};
// Create a type alias for Node pointers
typedef Node *Nodeptr;
// Constructor for initializing the list
DList ();
// Destructor for cleaning up memory
~DList ();
// Copy constructor to create a copy of another list
DList (const DList & other);
// Check if the list is empty
bool empty () const;
// Get the data in the first node
T headElement () const;
// Get the data in the last node
T tailElement () const;
// Get the data at a specific index
T getAt (int idx);
// Add a new node at the beginning of the list
void addHead (const T & newdata);
// Delete the first node
void delHead ();
// Add a new node at the end of the list
void addTail (const T & newdata);
// Delete the last node
void delTail ();
// Add a new node at a specific index
void addAt (int idx, const T & newdata);
// Delete the node at a specific index
void delAt (int idx);
// Get the length of the list
int length () const;
// Print the elements of the list
void print () const;
// Clear the entire list
void Clear ();
private:
// Helper function to create a dummy head node
void createDummyHead ();
// Helper function to navigate to a specific index
Nodeptr goToIndex (int idx);
// Pointer to the dummy head node
Nodeptr head;
};
#endif
#include <iostream>
using namespace std;
#include "dlist.h"
int main ()
{
DList::DList<int> L;//error...
L.print();