Adsa Assignment 1
Adsa Assignment 1
ASSIGNMENT 1
Name-Raghvender Tyagi
Roll No-2024PAI7329
1. Reverse linked list without using extra space.
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
next = curr->next;
curr->next = prev;
prev = curr;
curr = next;
}
return prev;
}
int main() {
head = reverseList(head);
return 0;
}
OUTPUT:
2. Reverse the nodes in a linked list present between some
random points P and Q in a linked list.
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node *next;
};
int i = 1;
struct Node *currNode = head;
while (currNode && i <= n) {
if (i < m)
revs_prev = currNode;
if (i == m)
revs = currNode;
if (i == n) {
revend = currNode;
revend_next = currNode->next;
}
currNode = currNode->next;
i++;
}
revend->next = NULL;
revend = reverse(revs);
if (revs_prev)
revs_prev->next = revend;
else
head = revend;
revs->next = revend_next;
return head;
}
int main() {
return 0;
}
OUTPUT:
3.Find the middle of the linked list
a) ODD LENGTH
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
int list_values[100];
int size = 0;
int main() {
return 0;
}
OUTPUT:
b) EVEN LENGTH
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
int list_values[100];
int size = 0;
int main() {
return 0;
}
OUTPUT: