#include <iostream>
using namespace std;
class Node{
public:
int value;
Node* next;
Node(int value){
this->value=value;
this->next=NULL;
}
};
class LinkedList{
private:
Node* head;
Node* tail;
int length;
public:
LinkedList(int value){
Node* newnode= new Node(value);
head=newnode;
tail=newnode;
length=1;
}
~LinkedList(){
Node* temp=head;
while(head!=nullptr){
head=head->next;
delete temp;
temp=head;
}
}
void printlist(){
Node* temp=head;
while(temp!=NULL){
cout<<temp->value<<" ";
temp=temp->next;
}
cout<<endl;
}
void getHead(){
if(head==nullptr) cout<<"Head: nullptr"<<endl;
else cout<< " Head: " <<head->value<<endl;
}
void getTail(){
if(tail==nullptr)
cout<<"Tail: nullptr"<<endl;
else
cout<<"Tail: "<<tail->value<<endl;
}
void getLength(){
cout<<"Length: "<<length<<endl;
}
void Append(int value){
Node* newnode= new Node(value);
if(head==nullptr){
head=newnode;
tail=newnode;
}
else{
tail->next=newnode;
tail=newnode;
}
length++;
}
void Prepend(int value){
Node* newnode= new Node(value);
if(head==nullptr){
head=newnode;
tail=newnode;
}
else{
newnode->next=head;
head=newnode;
}
length++;
}
Node* get(int index){
if(index < 0 || index>=length) return nullptr;
Node* temp=head;
for(int i=0;i < index;i++){
temp=temp->next;
}
return temp;
}
bool set(int index,int value){
Node* temp=get(index);
if(temp!=nullptr){
temp->value=value;
return true;
}
return false;
}
};
int main() {
LinkedList* myLL= new LinkedList(7);
myLL->Append(9);
myLL->Append(4);
myLL->getHead();
myLL->getTail();
myLL->getLength();
cout<<"Linked List before prepend: ";
myLL->printlist();
myLL->Prepend(2);
cout<<"Linked List after prepend: ";
myLL->printlist();
myLL->set(2,6);
cout<<"Linked List after set: ";
myLL->printlist();
return 0;

}