Name Anurag Yadav STUDENT ID 202212095 M.SC It SEM-1 LAB02 1.reverse Singly List
Name Anurag Yadav STUDENT ID 202212095 M.SC It SEM-1 LAB02 1.reverse Singly List
STUDENT ID=202212095
M.Sc IT
SEM-1
LAB02
#include<iostream>
using namespace std;
struct node {
int data;
struct node* next;
};
int main() {
struct node* head = NULL;
insert(&head, 1);
insert(&head, 3);
insert(&head, 2);
insert(&head, 5);
insert(&head, 4);
cout << "Linked List Before Reversing" << endl;
printnodes(head);
reverse(&head);
cout << endl;
cout << "Linked List After Reversing" << endl;
printnodes(head);
return 0;
}
Node* next_next;
if (current == NULL)
return;
new_node->data = new_data;
new_node->next = (*head_ref);
(*head_ref) = new_node;
}
void printList(Node* node)
{
while (node != NULL)
{
cout << " " << node->data;
node = node->next;
}
}
int main()
{
Node* head = NULL;
push(&head, 4);
push(&head, 4);
push(&head, 3);
push(&head, 2);
push(&head, 2);
push(&head, 1);
removeDuplicates(head);
return 0;
}
#include <iostream>
struct node {
int data;
struct node* next;
};
void push(struct node** head_ref, int data) {
struct node* ptr1 = (struct node*)malloc(sizeof(struct node));
struct node* temp = *head_ref;
ptr1->data = data;
ptr1->next = *head_ref;
if (*head_ref != NULL) {
while (temp->next != *head_ref) {
temp = temp->next;
}
temp->next = ptr1;
}
else {
ptr1->next = ptr1;
}
*head_ref = ptr1;
}
include<iostream>
using namespace std;
struct Node {
int data;
struct Node* next;
struct Node* prev;
};
if (*head_ref == del)
*head_ref = del->next;
if (del->next != NULL)
del->next->prev = del->prev;
if (del->prev != NULL)
del->prev->next = del->next;
free(del);
}
if (current == NULL)
return;
deleteNode(head_ref, current);
}
new_node->data = new_data;
new_node->prev = NULL;
new_node->next = (*head_ref);
if ((*head_ref) != NULL)
(*head_ref)->prev = new_node;
(*head_ref) = new_node;
}
push(&head, 5);
push(&head, 4);
push(&head, 3);
push(&head, 2);
push(&head, 1);
cout << "Doubly linked list before deletion: ";
printList(head);
int n;
cout <<endl<< "enter n=";
cin >> n;
cout << endl;
deleteNodeAtGivenPos(&head, n);
return 0;
}
struct node
{
int num;
node* nextptr;
}*stnode;
void make(int n)
{
struct node* frntNode, * tmp;
int num, i;
if (frntNode == NULL)
{
cout << "Memory can not be allocated";
break;
}
else
{
cout << "Enter the data for node= " << i << ": ";
cin >> num;
frntNode->num = num;
frntNode->nextptr = NULL;
tmp->nextptr = frntNode;
tmp = tmp->nextptr;
}
}
}
}
void print()
{
struct node* tmp;
if (stnode == NULL)
{
cout << "List is empty";
}
else
{
tmp = stnode;
cout << "Linked List=\t";
while (tmp != NULL)
{
cout << tmp->num << "\t";
tmp = tmp->nextptr;
}
}
}
void printMiddle(struct node* stnode)
{
struct node* single_ptr = stnode;
struct node* twice_ptr = stnode;
if (stnode != NULL)
{
while (twice_ptr != NULL && twice_ptr->nextptr != NULL)
{
twice_ptr = twice_ptr->nextptr->nextptr;
single_ptr = single_ptr->nextptr;
}
cout <<endl<< "The middle element is= " << single_ptr->num;
}
}
int main()
{
int n, num;
return 0;
}