#include<iostream>
using namespace std;
class Node{
public:
int data;
//Constructor
Node(int data){
this -> data=data;
}
};
void insertAtHead(Node* &head, int d){
Node* temp= new Node(d);
head=temp;
}
void insertAtTail(Node* &tail,int d){
Node *temp = new Node(d);
tail=temp;
}
void print(Node* &head){
Node* temp=head;
while(temp!=NULL){
cout<<temp->data<<" ";
}
cout<<endl;
}
int main(){
//created a new node
Node* node1 = new Node(10);
// cout<< node1 -> data<<endl;
// cout<< node1 -> next<<endl;
//head pointed to node1
Node* head = node1;
Node *tail = node1;
print(head);
// insertAtHead(head,12);
insertAtTail(tail,12);
print(head);
// insertAtHead(head,25);
insertAtTail(tail,15);
print(head);
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpjbGFzcyBOb2RlewogICAgcHVibGljOgogICAgaW50IGRhdGE7CiAgICBOb2RlKiBuZXh0OwoKICAgIC8vQ29uc3RydWN0b3IKCiAgICBOb2RlKGludCBkYXRhKXsKICAgICAgICB0aGlzIC0+IGRhdGE9ZGF0YTsKICAgICAgICB0aGlzIC0+IG5leHQ9TlVMTDsKICAgIH0KfTsKCgp2b2lkIGluc2VydEF0SGVhZChOb2RlKiAmaGVhZCwgaW50IGQpewogICAgICAgIE5vZGUqIHRlbXA9IG5ldyBOb2RlKGQpOwogICAgICAgIHRlbXAtPm5leHQ9aGVhZDsKICAgICAgICBoZWFkPXRlbXA7Cgp9CnZvaWQgaW5zZXJ0QXRUYWlsKE5vZGUqICZ0YWlsLGludCBkKXsKICAgIE5vZGUgKnRlbXAgPSBuZXcgTm9kZShkKTsKICAgIHRhaWwtPm5leHQgPSB0ZW1wOwogICAgdGFpbD10ZW1wOwp9Cgp2b2lkIHByaW50KE5vZGUqICZoZWFkKXsKICAgICAgICBOb2RlKiB0ZW1wPWhlYWQ7CgogICAgICAgIHdoaWxlKHRlbXAhPU5VTEwpewogICAgICAgICAgICBjb3V0PDx0ZW1wLT5kYXRhPDwiICI7CiAgICAgICAgICAgIHRlbXA9dGVtcC0+bmV4dDsKCgogICAgICAgIH0KICAgICAgICBjb3V0PDxlbmRsOwoKfQoKCgoKCmludCBtYWluKCl7CgogICAgLy9jcmVhdGVkIGEgbmV3IG5vZGUKCiAgICBOb2RlKiBub2RlMSA9IG5ldyBOb2RlKDEwKTsKICAgIC8vIGNvdXQ8PCBub2RlMSAtPiBkYXRhPDxlbmRsOwogICAgLy8gY291dDw8IG5vZGUxIC0+IG5leHQ8PGVuZGw7CgogICAgLy9oZWFkIHBvaW50ZWQgdG8gbm9kZTEKCiAgICBOb2RlKiBoZWFkID0gbm9kZTE7CiAgICBOb2RlICp0YWlsID0gbm9kZTE7CiAgICBwcmludChoZWFkKTsKCiAgICAvLyBpbnNlcnRBdEhlYWQoaGVhZCwxMik7CiAgICBpbnNlcnRBdFRhaWwodGFpbCwxMik7CgogICAgcHJpbnQoaGVhZCk7CgogICAgLy8gaW5zZXJ0QXRIZWFkKGhlYWQsMjUpOwogICAgaW5zZXJ0QXRUYWlsKHRhaWwsMTUpOwogICAgcHJpbnQoaGVhZCk7CgogICAgcmV0dXJuIDA7CiAgICAKCn0=
#include<iostream>
using namespace std;
class Node{
public:
int data;
Node* next;
//Constructor
Node(int data){
this -> data=data;
this -> next=NULL;
}
};
void insertAtHead(Node* &head, int d){
Node* temp= new Node(d);
temp->next=head;
head=temp;
}
void insertAtTail(Node* &tail,int d){
Node *temp = new Node(d);
tail->next = temp;
tail=temp;
}
void print(Node* &head){
Node* temp=head;
while(temp!=NULL){
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
int main(){
//created a new node
Node* node1 = new Node(10);
// cout<< node1 -> data<<endl;
// cout<< node1 -> next<<endl;
//head pointed to node1
Node* head = node1;
Node *tail = node1;
print(head);
// insertAtHead(head,12);
insertAtTail(tail,12);
print(head);
// insertAtHead(head,25);
insertAtTail(tail,15);
print(head);
return 0;
}