#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
/*===========================Singly Linked List=============================*/

//containing a address of the next item and the current item
class Node{
    public:
        Node* next_item;
        int data;
};


class LinkedList{
    public:
        int size;
        Node* head;
        void insert(int size);
        void _delete(int index);
        void print();
    LinkedList();
    ~LinkedList();
};



LinkedList::LinkedList(){
    this->size = 0;
    this->head = NULL;
}

LinkedList::~LinkedList(){
    std::cout<< "List Destroyed "<<std::endl;
}

//populated the list with random numbers within 1-100
//random number are called random for a reason you can't have them in
// acessding order unless you sort them yourself
void LinkedList::insert(int size){
    std::vector<int> data;
    for (int x=0;x<size;x++)
    {
        data.push_back((rand()%100)+1);
    }
    sort(data.begin(), data.end());
    for (auto x : data) {
        Node* node = new Node();
        node->data = x;
        node->next_item = this->head;
        this->head = node;
        this->size++;
    }
}

//delete  element in a specific index
void LinkedList::_delete(int index){
    Node *current=new Node();
    Node *previous=new Node();
    current=this->head;

    for(int i=1;i<index;i++)
    {
      previous=current;
      current=current->next_item;
    }
    previous->next_item=current->next_item;  
}

void LinkedList::print(){
    Node* head = this->head;
    int i = 1;
    while(head){
        std::cout<<"index " << i << "  has " << head->data << std::endl;
        head = head->next_item;
        i++;
    }
}