1

I am gettin some errors while i am trying to implement linked list with template way. I couldn't solve the problem for 4-5 hours. Gonna be crazy ..

I am taking error messsage when i tried to create an object. Taking same error in stack implement..

1>Kaynak1.obj : error LNK2001: Çözümlenmemiş dış sembol "public: __thiscall linkedlist::~linkedlist(void)" (??1?$linkedlist@H@@QAE@XZ) 1>Kaynak1.obj : error LNK2001: Çözümlenmemiş dış sembol "public: __thiscall linkedlist::linkedlist(void)" (??0?$linkedlist@H@@QAE@XZ)

My head file is :

#pragma once
#include<iostream>
#include<cassert>
using namespace std;
template <typename Type1>
struct node
{
    Type1 data;
    node* link;
};
template <class Type>
class linkedlist {
    node <Type> *first, *last;
    int count;
public:
    linkedlist();
    linkedlist(linkedlist&);
    void initializeList();
    int length()const;
    bool isEmptyList()const;
    void print()const;

    Type front()const;
    Type back()const;
    bool search(Type) const;
    void insertFirst(Type);
    void insertLast(Type);
    void deleteNode(Type);
    ~linkedlist();
};

And my implement file;

#include"Üst Bilgi.h"
template <class Type>
linkedlist<Type>::linkedlist() {
    first = NULL;
    last = NULL;
    count = 0;
}
template <class Type>
int linkedlist<Type>::length()const {
    return count;
}
template <class Type>
bool linkedlist<Type>::isEmptyList()const {
    return count == 0;
}
template <class Type>
Type linkedlist<Type>::front()const {
    assert(first != NULL);
    return first->data;
}
template <class Type>
Type linkedlist<Type>::back()const {
    assert(last != NULL);
    return last->data;
}
template <class Type>
void linkedlist<Type>::print()const {
    node *temp = first;

    if (temp == NULL)
    {
        cout << "Empty list..." << endl;
    }
    else
    {
        while (temp != NULL)
        {
            cout << temp->data << endl;
            temp = temp->link;
        }
    }
}
template <class Type>
void linkedlist<Type>::insertFirst(Type value) {

    node <Type1> *valuenode = new node;

    valuenode->data = value;
    valuenode->link = NULL;

    valuenode->link = first;
    first = valuenode;

    if (last == NULL)
    {
        last = valuenode;
    }
    count++;
}
template <class Type>
void linkedlist<Type>::insertLast(Type value) {
    node *valuenode = new node;

    valuenode->data = value;
    valuenode->link = NULL;

    if (last == NULL) {
        first = last = valuenode;
    }
    else
    {
        last->link = valuenode;
        last = valuenode;
    }
    count++;
}
template <class Type>
linkedlist<Type>::~linkedlist() {

    node* temp = first;

    while (temp != NULL)
    {
        first = first->link;
        delete temp;
        temp = first;
    }
    last = NULL;
    count = 0;
}
template <class Type>
linkedlist<Type>::linkedlist(linkedlist &other) {

    if (other.first == NULL)
    {
        first = last = NULL;
        count = 0;
    }
    else
    {
        count = other.count;
        first = new node;
        first->data = other.first->data;
        first->link = NULL;
        last = first;

        node *current = other.first->link;

        while (current != NULL)
        {
            insertLast(current->data);
            current = current->link;
        }
    }
}
template <class Type>
bool linkedlist<Type>::search(Type value)const {

    bool found = false;

    node *temp = first;

    while (temp != NULL)
    {
        if (temp->data == value)
        {
            found = true;
            break;
        }
        temp = temp->link;
    }

    return found;
}
template <class Type>
void linkedlist<Type>::initializeList() {

    node *temp = first;
    while (temp != NULL)
    {
        first = first->link;
        delete temp;
        temp = first;
    }
    last = NULL; count = 0;
}
template <class Type>
void linkedlist<Type>::deleteNode(Type value) {

    bool isfound = search(value);
    node *temp = first;

    if (isfound)
    {
        if (first == last)
        {
            delete temp;
            count = 0;
            last = NULL;
        }
        else if (first->data == value) {
            first = first->link;
            delete temp;
            temp = first;
            count--;
        }
        else if (last->data == value)
        {
            node *rtemp = temp;
            while (temp->link != NULL)
            {
                rtemp = temp;
                temp = temp->link;
            }
            last = rtemp;
            delete temp;

            last->link = NULL;
            count--;
        }
        else
        {
            node *rtemp = temp;
            while (temp->link != NULL)
            {
                rtemp = temp;
                temp = temp->link;
                if (temp->data == value)
                {
                    break;
                }
            }
            rtemp->link = temp->link;
            delete temp;
            count--;
        }
    }
}

0 Answers0