Professional Documents
Culture Documents
Maria DS 21510102 - 3
Maria DS 21510102 - 3
No #3
#include<bits/stdc++.h>
#define maria main
#define emp emplace_back
#define int long long int
using namespace std;
class Node{
public:
int data;
Node* next;
Node(int data){
this->data=data;
this->next=NULL;
}
};
void print(Node* &head){
Node* temp=head;
while (temp!=NULL){
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
void inathead(Node* &head,int data){
Node* temp=new Node(data);
temp->next=head;
head=temp;
}
void inattail(Node* &head,int data){
Node* temp=head;
while (temp->next!=NULL){
temp=temp->next;
}
Node* ptr=new Node(data);
temp->next=ptr;
ptr->next=NULL;
}
void reversell(Node* &head){
Node* f=head;
Node* pre=NULL;
Node* s;
while(f!=NULL){
s=f->next;
f->next=pre;
pre=f;
f=s;
}
head=pre;
}
int32_t maria(){
Node* node1=new Node(10);
Node* head=node1;
head=node1;
inathead(head,15);//inserting at head
inattail(head,18);//inserting at tail
inatpos(head,3,424);//inserting at particular position
cout<<"Original Linked List:-";
print(head);
cout<<"After reverse the Linked List become:-";
reversell(head);//reversing the linked list
print(head);
cout<<endl;
return 0;
}
Output:-