Assignment 2 1484
Assignment 2 1484
(ADVANCED CODING)
A. Prathibha naidu
VU21CSEN0101484
1. Reverse a linked list: Given a linked list, reverse the linked lst and return the
pointer to the reversed list.
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
// Crea ng the linked list 1 -> 2 -> 3 -> 4 -> NULL
struct ListNode* head = createNode(1); head-
>next = createNode(2); head->next->next =
createNode(3);
head->next->next->next = createNode(4);
return 0;
}
Output:
tf
tf
tf
tf
ti
ti
2)Remove fullstops from a string: Given a string with
alphanumeric characters and fullstops, write a
program to remove the fullstops from the string.
Code:
#include <stdio.h>
#include <string.h>
return 0;
}
Output:
Code:
#include <stdio.h>
#include <stdlib.h>
return slow; // slow will be at the middle when fast reaches the
end
}
return 0;
}
Output:
4.) Maximum odd-even sum of a linked list: Given a
linkedlist, find the maximum sum sum of pairs of
alternate elements.
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
// Creating the linked list 1 -> 2 -> 3 -> 4 -> 5 ->
NULL
struct ListNode* head = createNode(1); head->next =
createNode(2); head->next->next = createNode(3);
head->next->next->next = createNode(4); head->next-
>next->next->next = createNode(5);
return 0;
}
Output: