Skip to main content
Rollback to Revision 1
Source Link
Phrancis
  • 20.5k
  • 6
  • 70
  • 155

EDIT:

Following the advice of others from below, here is my new code:

#ifndef LinkedList_hpp
#define LinkedList_hpp

#include <iostream>

template<class T>
struct Node {
    T data;
    Node<T>* next;
};

template<class T>
class SingleLinkedList {
private:
    Node<T>* head;
    Node<T>* tail;

public:
    SingleLinkedList() : head(nullptr), tail(nullptr) {}
    
    SingleLinkedList(SingleLinkedList const& value) : head(nullptr), tail(nullptr) {
        for(Node<T>* loop = value->head; loop != nullptr; loop = loop->next) {
            createNode(loop->data);
        }
    }
    
    SingleLinkedList& operator=(SingleLinkedList const& rhs) { SingleLinkedList copy(rhs);}
    
     void swap(SingleLinkedList& other) noexcept {
         using std::swap;
         swap(head, other.head);
         swap(tail, other.tail);
     }
    
    ~SingleLinkedList(){
        Node<T>* nodePtr = head;
        while(nodePtr != nullptr) {
            Node<T>* nextNode = nodePtr->next;
            nodePtr = nextNode;
            delete nodePtr;
        }
    }
    
    void createNode(const T&& theData) {
        Node<T>* temp = new Node<T>;
        temp->data = std::move(theData);
        temp->next = nullptr;
        if(head == nullptr) {
            head = temp;
            tail = temp;
            temp = nullptr;
        }
        else {
            tail->next = temp;
            tail = temp;
        }
    }
    
    void display(std::ostream& str = std::cout) {
        Node<T>* temp = head;
        while(temp != nullptr) {
            str << temp->data << "\t";
            temp = temp->next;
        }
        delete temp;
    }
    
    void insert_start(const T& theData) {
        Node<T>* temp = new Node<T>;
        temp->data = theData;
        temp->next = head;
        head = temp;
        delete temp;
    }
    
    void insert_position(int pos, const T& theData) {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        Node<T>* temp = new Node<T>;
        current = head;
        for(int i  = 1; i < pos; i++) {
            previous = current;
            current = current->next;
        }
        temp->data = theData;
        previous->next = temp;
        temp->next = current;
    }
    
    void delete_first() {
        Node<T>* temp = head;
        head = head->next;
        delete temp;
    }
    
    void delete_last() {
        Node<T>* previous = nullptr;
        Node<T>* current = nullptr;
        current = head;
        while(current->next != nullptr) {
            previous = current;
            current = current->next;
        }
        tail = previous;
        previous->next = nullptr;
        delete current;
    }
    
    void delete_position(int pos) {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        current = head;
        for(int i = 1; i < pos; i++) {
            previous = current;
            current = current->next;
        }
        previous->next = current->next;
    }
    
    bool search(const T& x) {
        struct Node<T>* current = head;  
        while (current != NULL) {
            if (current->data == x)
                return true;
            current = current->next;
        }
        return false;
    }
    
    friend std::ostream& operator<<(std::ostream& str, SingleLinkedList& data) {
        data.display(str);
        return str;
    }
};

Here is the new main.cpp:

#include <iostream>
#include "LinkedList.hpp"


int main(int argc, const char * argv[]) {
    
    SingleLinkedList<int> obj;
    obj.createNode(2);
    obj.createNode(4);
    obj.createNode(6);
    obj.createNode(8);
    obj.createNode(10);
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"---------------Displaying All nodes---------------";
    std::cout<<"\n--------------------------------------------------\n";
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"-----------------Inserting At End-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.createNode(55);
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Inserting At Start----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.insert_start(50);
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"-------------Inserting At Particular--------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.insert_position(5,60);
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Deleting At Start-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_first();
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Deleting At End-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_last();
    std::cout << obj << std::endl;
    
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"--------------Deleting At Particular--------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_position(4);
    std::cout << obj << std::endl;
    std::cout << std::endl;
    
    obj.search(8) ? std::cout << "Yes" << std::endl : std::cout << "No" << std::endl;;
    

    
    return 0;
}

EDIT:

Following the advice of others from below, here is my new code:

#ifndef LinkedList_hpp
#define LinkedList_hpp

#include <iostream>

template<class T>
struct Node {
    T data;
    Node<T>* next;
};

template<class T>
class SingleLinkedList {
private:
    Node<T>* head;
    Node<T>* tail;

public:
    SingleLinkedList() : head(nullptr), tail(nullptr) {}
    
    SingleLinkedList(SingleLinkedList const& value) : head(nullptr), tail(nullptr) {
        for(Node<T>* loop = value->head; loop != nullptr; loop = loop->next) {
            createNode(loop->data);
        }
    }
    
    SingleLinkedList& operator=(SingleLinkedList const& rhs) { SingleLinkedList copy(rhs);}
    
     void swap(SingleLinkedList& other) noexcept {
         using std::swap;
         swap(head, other.head);
         swap(tail, other.tail);
     }
    
    ~SingleLinkedList(){
        Node<T>* nodePtr = head;
        while(nodePtr != nullptr) {
            Node<T>* nextNode = nodePtr->next;
            nodePtr = nextNode;
            delete nodePtr;
        }
    }
    
    void createNode(const T&& theData) {
        Node<T>* temp = new Node<T>;
        temp->data = std::move(theData);
        temp->next = nullptr;
        if(head == nullptr) {
            head = temp;
            tail = temp;
            temp = nullptr;
        }
        else {
            tail->next = temp;
            tail = temp;
        }
    }
    
    void display(std::ostream& str = std::cout) {
        Node<T>* temp = head;
        while(temp != nullptr) {
            str << temp->data << "\t";
            temp = temp->next;
        }
        delete temp;
    }
    
    void insert_start(const T& theData) {
        Node<T>* temp = new Node<T>;
        temp->data = theData;
        temp->next = head;
        head = temp;
        delete temp;
    }
    
    void insert_position(int pos, const T& theData) {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        Node<T>* temp = new Node<T>;
        current = head;
        for(int i  = 1; i < pos; i++) {
            previous = current;
            current = current->next;
        }
        temp->data = theData;
        previous->next = temp;
        temp->next = current;
    }
    
    void delete_first() {
        Node<T>* temp = head;
        head = head->next;
        delete temp;
    }
    
    void delete_last() {
        Node<T>* previous = nullptr;
        Node<T>* current = nullptr;
        current = head;
        while(current->next != nullptr) {
            previous = current;
            current = current->next;
        }
        tail = previous;
        previous->next = nullptr;
        delete current;
    }
    
    void delete_position(int pos) {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        current = head;
        for(int i = 1; i < pos; i++) {
            previous = current;
            current = current->next;
        }
        previous->next = current->next;
    }
    
    bool search(const T& x) {
        struct Node<T>* current = head;  
        while (current != NULL) {
            if (current->data == x)
                return true;
            current = current->next;
        }
        return false;
    }
    
    friend std::ostream& operator<<(std::ostream& str, SingleLinkedList& data) {
        data.display(str);
        return str;
    }
};

Here is the new main.cpp:

#include <iostream>
#include "LinkedList.hpp"


int main(int argc, const char * argv[]) {
    
    SingleLinkedList<int> obj;
    obj.createNode(2);
    obj.createNode(4);
    obj.createNode(6);
    obj.createNode(8);
    obj.createNode(10);
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"---------------Displaying All nodes---------------";
    std::cout<<"\n--------------------------------------------------\n";
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"-----------------Inserting At End-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.createNode(55);
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Inserting At Start----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.insert_start(50);
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"-------------Inserting At Particular--------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.insert_position(5,60);
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Deleting At Start-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_first();
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Deleting At End-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_last();
    std::cout << obj << std::endl;
    
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"--------------Deleting At Particular--------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_position(4);
    std::cout << obj << std::endl;
    std::cout << std::endl;
    
    obj.search(8) ? std::cout << "Yes" << std::endl : std::cout << "No" << std::endl;;
    

    
    return 0;
}
added 6743 characters in body
Source Link
Snorrlaxxx
  • 793
  • 5
  • 15

EDIT:

Following the advice of others from below, here is my new code:

#ifndef LinkedList_hpp
#define LinkedList_hpp

#include <iostream>

template<class T>
struct Node {
    T data;
    Node<T>* next;
};

template<class T>
class SingleLinkedList {
private:
    Node<T>* head;
    Node<T>* tail;

public:
    SingleLinkedList() : head(nullptr), tail(nullptr) {}
    
    SingleLinkedList(SingleLinkedList const& value) : head(nullptr), tail(nullptr) {
        for(Node<T>* loop = value->head; loop != nullptr; loop = loop->next) {
            createNode(loop->data);
        }
    }
    
    SingleLinkedList& operator=(SingleLinkedList const& rhs) { SingleLinkedList copy(rhs);}
    
     void swap(SingleLinkedList& other) noexcept {
         using std::swap;
         swap(head, other.head);
         swap(tail, other.tail);
     }
    
    ~SingleLinkedList(){
        Node<T>* nodePtr = head;
        while(nodePtr != nullptr) {
            Node<T>* nextNode = nodePtr->next;
            nodePtr = nextNode;
            delete nodePtr;
        }
    }
    
    void createNode(const T&& theData) {
        Node<T>* temp = new Node<T>;
        temp->data = std::move(theData);
        temp->next = nullptr;
        if(head == nullptr) {
            head = temp;
            tail = temp;
            temp = nullptr;
        }
        else {
            tail->next = temp;
            tail = temp;
        }
    }
    
    void display(std::ostream& str = std::cout) {
        Node<T>* temp = head;
        while(temp != nullptr) {
            str << temp->data << "\t";
            temp = temp->next;
        }
        delete temp;
    }
    
    void insert_start(const T& theData) {
        Node<T>* temp = new Node<T>;
        temp->data = theData;
        temp->next = head;
        head = temp;
        delete temp;
    }
    
    void insert_position(int pos, const T& theData) {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        Node<T>* temp = new Node<T>;
        current = head;
        for(int i  = 1; i < pos; i++) {
            previous = current;
            current = current->next;
        }
        temp->data = theData;
        previous->next = temp;
        temp->next = current;
    }
    
    void delete_first() {
        Node<T>* temp = head;
        head = head->next;
        delete temp;
    }
    
    void delete_last() {
        Node<T>* previous = nullptr;
        Node<T>* current = nullptr;
        current = head;
        while(current->next != nullptr) {
            previous = current;
            current = current->next;
        }
        tail = previous;
        previous->next = nullptr;
        delete current;
    }
    
    void delete_position(int pos) {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        current = head;
        for(int i = 1; i < pos; i++) {
            previous = current;
            current = current->next;
        }
        previous->next = current->next;
    }
    
    bool search(const T& x) {
        struct Node<T>* current = head;  
        while (current != NULL) {
            if (current->data == x)
                return true;
            current = current->next;
        }
        return false;
    }
    
    friend std::ostream& operator<<(std::ostream& str, SingleLinkedList& data) {
        data.display(str);
        return str;
    }
};

Here is the new main.cpp:

#include <iostream>
#include "LinkedList.hpp"


int main(int argc, const char * argv[]) {
    
    SingleLinkedList<int> obj;
    obj.createNode(2);
    obj.createNode(4);
    obj.createNode(6);
    obj.createNode(8);
    obj.createNode(10);
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"---------------Displaying All nodes---------------";
    std::cout<<"\n--------------------------------------------------\n";
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"-----------------Inserting At End-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.createNode(55);
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Inserting At Start----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.insert_start(50);
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"-------------Inserting At Particular--------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.insert_position(5,60);
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Deleting At Start-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_first();
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Deleting At End-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_last();
    std::cout << obj << std::endl;
    
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"--------------Deleting At Particular--------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_position(4);
    std::cout << obj << std::endl;
    std::cout << std::endl;
    
    obj.search(8) ? std::cout << "Yes" << std::endl : std::cout << "No" << std::endl;;
    

    
    return 0;
}

EDIT:

Following the advice of others from below, here is my new code:

#ifndef LinkedList_hpp
#define LinkedList_hpp

#include <iostream>

template<class T>
struct Node {
    T data;
    Node<T>* next;
};

template<class T>
class SingleLinkedList {
private:
    Node<T>* head;
    Node<T>* tail;

public:
    SingleLinkedList() : head(nullptr), tail(nullptr) {}
    
    SingleLinkedList(SingleLinkedList const& value) : head(nullptr), tail(nullptr) {
        for(Node<T>* loop = value->head; loop != nullptr; loop = loop->next) {
            createNode(loop->data);
        }
    }
    
    SingleLinkedList& operator=(SingleLinkedList const& rhs) { SingleLinkedList copy(rhs);}
    
     void swap(SingleLinkedList& other) noexcept {
         using std::swap;
         swap(head, other.head);
         swap(tail, other.tail);
     }
    
    ~SingleLinkedList(){
        Node<T>* nodePtr = head;
        while(nodePtr != nullptr) {
            Node<T>* nextNode = nodePtr->next;
            nodePtr = nextNode;
            delete nodePtr;
        }
    }
    
    void createNode(const T&& theData) {
        Node<T>* temp = new Node<T>;
        temp->data = std::move(theData);
        temp->next = nullptr;
        if(head == nullptr) {
            head = temp;
            tail = temp;
            temp = nullptr;
        }
        else {
            tail->next = temp;
            tail = temp;
        }
    }
    
    void display(std::ostream& str = std::cout) {
        Node<T>* temp = head;
        while(temp != nullptr) {
            str << temp->data << "\t";
            temp = temp->next;
        }
        delete temp;
    }
    
    void insert_start(const T& theData) {
        Node<T>* temp = new Node<T>;
        temp->data = theData;
        temp->next = head;
        head = temp;
        delete temp;
    }
    
    void insert_position(int pos, const T& theData) {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        Node<T>* temp = new Node<T>;
        current = head;
        for(int i  = 1; i < pos; i++) {
            previous = current;
            current = current->next;
        }
        temp->data = theData;
        previous->next = temp;
        temp->next = current;
    }
    
    void delete_first() {
        Node<T>* temp = head;
        head = head->next;
        delete temp;
    }
    
    void delete_last() {
        Node<T>* previous = nullptr;
        Node<T>* current = nullptr;
        current = head;
        while(current->next != nullptr) {
            previous = current;
            current = current->next;
        }
        tail = previous;
        previous->next = nullptr;
        delete current;
    }
    
    void delete_position(int pos) {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        current = head;
        for(int i = 1; i < pos; i++) {
            previous = current;
            current = current->next;
        }
        previous->next = current->next;
    }
    
    bool search(const T& x) {
        struct Node<T>* current = head;  
        while (current != NULL) {
            if (current->data == x)
                return true;
            current = current->next;
        }
        return false;
    }
    
    friend std::ostream& operator<<(std::ostream& str, SingleLinkedList& data) {
        data.display(str);
        return str;
    }
};

Here is the new main.cpp:

#include <iostream>
#include "LinkedList.hpp"


int main(int argc, const char * argv[]) {
    
    SingleLinkedList<int> obj;
    obj.createNode(2);
    obj.createNode(4);
    obj.createNode(6);
    obj.createNode(8);
    obj.createNode(10);
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"---------------Displaying All nodes---------------";
    std::cout<<"\n--------------------------------------------------\n";
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"-----------------Inserting At End-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.createNode(55);
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Inserting At Start----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.insert_start(50);
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"-------------Inserting At Particular--------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.insert_position(5,60);
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Deleting At Start-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_first();
    std::cout << obj << std::endl;
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Deleting At End-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_last();
    std::cout << obj << std::endl;
    
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"--------------Deleting At Particular--------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_position(4);
    std::cout << obj << std::endl;
    std::cout << std::endl;
    
    obj.search(8) ? std::cout << "Yes" << std::endl : std::cout << "No" << std::endl;;
    

    
    return 0;
}
Source Link
Snorrlaxxx
  • 793
  • 5
  • 15

Generic single linked list

I am a mathematician attempting to become proficient with C++. At the moment I am learning about data structures. I am tried writing a single linked list from scratch with some help from online tutorials. I wanted to see if there is anything that I could improve so that I can study and understand everything.

Here is my code:

#ifndef LinkedList_hpp
#define LinkedList_hpp

#include <iostream>

template<class T>
struct Node {
    T data;
    Node<T>* next;
};

template<class T>
class SingleLinkedList {
private:
    Node<T>* head;
    Node<T>* tail;

public:
    SingleLinkedList() {
        head = nullptr;
        tail = nullptr;
    }
    
    ~SingleLinkedList(){
        std::cout << "Pointers deleted" << std::endl;
    }
    
    void createNode(const T& theData) {
        Node<T>* temp = new Node<T>;
        temp->data = theData;
        temp->next = nullptr;
        if(head == nullptr) {
            head = temp;
            tail = temp;
            temp = nullptr;
        }
        else {
            tail->next = temp;
            tail = temp;
        }
    }
    
    void display() {
        Node<T>* temp = head;
        while(temp != nullptr) {
            std::cout << temp->data << "\t";
            temp = temp->next;
        }
    }
    
    void insert_start(const T& theData) {
        Node<T>* temp = new Node<T>;
        temp->data = theData;
        temp->next = head;
        head = temp;
    }
    
    void insert_position(int pos, const T& theData) {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        Node<T>* temp = new Node<T>;
        current = head;
        for(int i  = 1; i < pos; i++) {
            previous = current;
            current = current->next;
        }
        temp->data = theData;
        previous->next = temp;
        temp->next = current;
    }
    
    void delete_first() {
        Node<T>* temp = head;
        head = head->next;
        delete temp;
    }
    
    void delete_last() {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        current = head;
        while(current->next != nullptr) {
            previous = current;
            current = current->next;
        }
        tail = previous;
        previous->next = nullptr;
        delete current;
    }
    
    void delete_position(int pos) {
        Node<T>* previous = new Node<T>;
        Node<T>* current = new Node<T>;
        current = head;
        for(int i = 1; i < pos; i++) {
            previous = current;
            current = current->next;
        }
        previous->next = current->next;
    }
    
    bool search(const T& x) {
        struct Node<T>* current = head;  
        while (current != NULL) {
            if (current->data == x)
                return true;
            current = current->next;
        }
        return false;
    }
};

#endif /* LinkedList_hpp */

#include <iostream>
#include "LinkedList.hpp"


int main(int argc, const char * argv[]) {
    
    SingleLinkedList<int> obj;
    obj.createNode(2);
    obj.createNode(4);
    obj.createNode(6);
    obj.createNode(8);
    obj.createNode(10);
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"---------------Displaying All nodes---------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.display();
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"-----------------Inserting At End-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.createNode(55);
    obj.display();
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Inserting At Start----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.insert_start(50);
    obj.display();
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"-------------Inserting At Particular--------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.insert_position(5,60);
    obj.display();
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"----------------Deleting At Start-----------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_first();
    obj.display();
    
    std::cout<<"\n--------------------------------------------------\n";
    std::cout<<"--------------Deleting At Particular--------------";
    std::cout<<"\n--------------------------------------------------\n";
    obj.delete_position(4);
    obj.display();
    std::cout << std::endl;
    
    obj.search(8) ? std::cout << "Yes" << std::endl : std::cout << "No" << std::endl;;
    

    
    return 0;
}