0% found this document useful (0 votes)
10 views4 pages

ADSA 3rd

Uploaded by

vivekkrpandit134
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

ADSA 3rd

Uploaded by

vivekkrpandit134
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 1.3
Student Name: UID:
Branch: Section/Group:
rd
Semester: 3 Sem Date of Performance:
Subject Name: Adv. Data Structure & Algorithm Subject Code: 23CSH-204

1. Aim: In a college's alumni association, two separate lists of alumni donations are
maintained. The first list contains the funds donated by alumni in a specific order, and
the second list represents another group of alumni with their donation numbers. Due to
some inconsistencies in the records, every third donation in the first list is found to be
erroneous and needs to be removed.

You are tasked with cleaning up the first list by removing every third donation. After
that, you need to identify the common donation number between the cleaned first list and
the second list. This will help the association identify alumni who have donated multiple
times.

2. Requirements(Hardware/Software):
 C++ compiler.

3. Procedure:
#include <iostream>

using namespace std;

struct Node {

int val;

Node *next;

Node(int v) : val(v), next(NULL) {}

};

void append(Node*& head, int val) {

if (!head) head = new Node(val);

else {
Node* temp = head;

while (temp->next) temp = temp->next;

temp->next = new Node(val);

void deleteEveryThird(Node*& head) {

Node *prev = NULL, *curr = head;

int count = 1;

while (curr) {

if (count % 3 == 0) {

prev->next = curr->next;

delete curr;

curr = prev->next;

} else {

prev = curr;

curr = curr->next;

count++;

void printCommon(Node* list1, Node* list2) {

while (list1) {

Node* temp = list2;

while (temp) {

if (list1->val == temp->val) {

cout << list1->val << " ";

break;

temp = temp->next;
}

list1 = list1->next;

void printList(Node* head) {

while (head) {

cout << head->val << " ";

head = head->next;

cout << "\n";

int main() {

int n1, n2, val;

cin >> n1;

Node *list1 = NULL, *list2 = NULL;

for (int i = 0; i < n1; ++i) {

cin >> val;

append(list1, val);

cin >> n2;

for (int i = 0; i < n2; ++i) {

cin >> val;

append(list2, val);

deleteEveryThird(list1);

cout << "First linked list after deleting every third node:\n";

printList(list1);
cout << "Common values between the two linked lists:\n";

printCommon(list1, list2);

return 0;

4. Output:

5. Learning Outcome:
 Learnt how to use of functions.
 Learnt how to call a function in the main function.
 Learnt the Linked List insertion and deletion.

You might also like