0

My code only contains 3 types of error which I have mentioned in the end ,see those error first then go through my code which is basically definition and declaration of linkedlist class im using VS studio IDE and im not sure im getting some silly error please help me with this

// DEFINITION

#ifndef LINKEDLIST_H
#define LINKEDLIST_H

template <class T>
class Node
{

public:
    T data;
    Node* next;

    Node(T val);
};

template <class T>
class Linkedlist
{
private:
    Node* head;
public:
    

    void insert_at_beg(T val);
    void insert_at_end(T val);
    void insert_at_i(T val,int i);

    void remove_at_beg();
    void remove_at_end();
    void remove_at_i(int i);

    T search(T val);

    bool isfull();
    void printlist();
};
#endif

// THIS IS DEFINITION OF FILE
#include "Linkedlist.h"
#include <iostream>
using namespace std;



// definition from Node class
template <class T>
Node::Node(T val)
    {
        data = val;
        next = NULL;
    }


// definition from linkedlist class

template <class T>
void Linkedlist::insert_at_beg(T val)
    {
        Node* ptr = new Node();
        ptr->data = val;


        if (head == NULL)
        {
            head = ptr;
            ptr->next = NULL;
        }

        else
        {
            Node* temp;
            temp = head;
            temp = temp->next;

            head = ptr;
            ptr->next = temp;
        }
    }

template <class T>
void Linkedlist::insert_at_end(T val)
    {
        Node* ptr = new Node();
        ptr->data = val;

        
        Node* temp;

        temp = head;
        while (temp->next != NULL)
        {
            temp = temp->next;
        }
        temp->next = ptr;
        ptr->next = NULL;
    }
    
template <class T>
void Linkedlist::insert_at_i(T val, int i)
    {
        Node* ptr = new Node();
        ptr->data = val;

        Node* temp = head;
        Node* prev_temp;
        int index = 0;
        while (index != i)
        {
            prev_temp = temp;
            temp = temp->next;
            index++;
        }

        prev_temp->next = ptr;
        ptr->next = temp;
    }

template <class T>
void Linkedlist::remove_at_beg()
    {
        Node* temp;
        temp = head;
        
        head = temp->next;

        free(temp);

    }

template <class T>
void Linkedlist::remove_at_end()
    {
        Node* temp;
        temp = head;

        Node* prev_temp;
        while (temp->next != NULL)
        {
            prev_temp = temp;
            temp = temp->next;
        }

        free(temp);
        prev_temp->next = NULL;
    }

template <class T>
void Linkedlist::remove_at_i(int i)
    {
        Node* temp = head;
        Node* prev_temp;
        Node* next_temp;
        
        int index = 0;
        while (index != i)
        {
            prev_temp = temp;
            temp = temp->next;
            index++;
        }

        next_temp = temp->next;

        prev_temp->next = next_temp;
        free(temp);
    }

template <class T>
T Linkedlist::search(T val)
    {
        Node* temp = head;
        while (temp->next != NULL)
        {
            if (temp->data == val)
            {
                return true;
            }
        }

        return false;
    }
template <class T>
bool Linkedlist::isfull()
    {
        
        if (head != NULL)
            return true;
        else
            return false;
    }

template <class T>
void Linkedlist::printlist()
    {
        Node* temp = head;
        while (temp->next != NULL)
        {
            cout << temp->data << "->";
        }
        cout << "NULL";
    }

/

/ THE ERROR I GET WHICH I CANT FIGURE OUT ,IM USING VISUAL STUDIO

these 3 are the only errors

like in 10 15 lines I get name followed by :: must be class or namespace 
which is  a class but not sure what wrong

other is class template requires template argument list Node::Node unable to match

unable to match function definition to existing declaration like Linkedlist::isfull()    // compare it with .h and .cpp file
daud nasir
  • 41
  • 4

0 Answers0