Manas Dsa
Manas Dsa
CODE:
#include<iostream>
using namespace std;
class node
{
public:
int data;
node* next;
node(int val)
{
data=val;
next=NULL;
}
};
void insertAtHead(node* &head, int val)
{
node* n=new node(val);
if(head==NULL)
{
n->next=n;
head=n;
Charvi Gupta 20102031 1
}
node* temp=head;
while(temp->next!=head)
{
temp=temp->next;
}
temp->next=n;
n->next=head;
head=n;
}
void insertAtTail(node* &head, int val)
{
if(head==NULL)
{
insertAtHead(head,val);
}
node* n=new node(val);
node* temp=head;
while(temp->next!=head)
{
temp=temp->next;
}
temp->next=n;
display(head);
cout<<endl<<search(head,3);
return 0;
}
A2
CODE:
// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
// Structure of a Node
struct Node {
int data;
// Backward traversal
cout << "\nTraversal in reverse"
" direction \n";
Node* last = start->prev;
temp = last;
// Function to construct a
// circular doubly linked list
Node* formLinkedList(Node* start)
{
// Given linked list as:
// 4 <-> 5 <-> 6 <-> 7 <-> 8
insertEnd(&start, 4);
insertEnd(&start, 5);
insertEnd(&start, 6);
insertEnd(&start, 7);
insertEnd(&start, 8);
// Function Call
updateNodeValue(start);
return 0;
}
A3
return;
}
int digitSum(int num)
{
int sum = 0;
while (num) {
sum += (num % 10);
num /= 10;
}
return sum;
}
Node* deleteEvenDigitSumNodes(Node* head)
{
struct Node* ptr = head;
A4
CODE:
// Charvi Gupta 20102031 Q4
#include <bits/stdc++.h>
using namespace std;
#define SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
class Node
{
public:
int data;
Node *next;
Node *child;
};
Node *createList(int *arr, int n)
{
Node *head = NULL;
Node *p;
int i;
for (i = 0; i < n; ++i)
{
if (head == NULL)
Node *tmp;
Node *tail = head;
while (tail->next != NULL)
tail = tail->next;
Node *cur = head;
while (cur != tail)
{
if (cur->child)
{
tail->next = cur->child;
tmp = cur->child;
while (tmp->next)
Charvi Gupta 20102031 17
tmp = tmp->next;
tail = tmp;
}
cur = cur->next;
}
}
int main(void)
{
Node *head = NULL;
cout<<"\n The required output is : \n";
head = createList();
flattenList(head);
printList(head);
return 0;
}