Write a java program using LinkedList to reverse a singly linked list in groups of a given size. We have to consider all consecutive groups, where each group contains elements, throughout the entire linked list starting from the first element. It may be possible that the last group may not contain k elements, in which case, we simply reverse the remaining elements. For example,
Inputs: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> NULL
and k = 3
.
Output: 3 -> 2 -> 1 -> 6 -> 5 -> 4 -> 8 -> 7 -> NULL
Write a java program using arrayList . Create a list and store some words in the list. Perform the following operations on the list:
- Display the list initially
- Reverse the list and display.
- Display the words in the list that end with ‘s’
- Remove the words that start with ‘a’ and end with ‘s’ and display the list
- Sort the list
Write a program to demonstrate the knowledge of students in working with Java collection framework. Eg., Assume only a maximum of 3 courses can be registered by a student for week end semester classes. Create a hashmap ‘h1’ with ‘n’ key-value pairs where keys are the names of students and values are the courses registered by them. Create another hashmap ‘h2’ with ‘m’key-value pairs where keys are the names of courses offered for B.Tech and values are the names of faculty handling the courses. Write appropriate code to
- Add or remove a student from h1
- Iterate over the maps and display the key-value pairs stored in them
- Given a student name, fetch the names of all those who teach him/her.