Archives: Logical Programs

Tower of Hanoi Game in Java

Problem: Write a program to solve the Tower of Hanoi puzzle, which involves moving disks from one peg to another while obeying certain rules. The Tower of Hanoi puzzle is a timeless challenge where players move disks between pegs following strict rules. It’s a captivating game that highlights key concepts like recursion and problem-solving strategies. …

Tower of Hanoi Game in Java Read More »

Queue Implementation using LinkedList

Problem Statement: Write a Java program to implement a basic queue using LinkedList to enqueue and dequeue elements. Here’s a basic implementation of a queue using a LinkedList in Java to enqueue and dequeue elements. OUTPUT: Queue Size: 3Dequeued Element: 1Dequeued Element: 2Queue Size after Dequeue: 1 Explanation: This basic queue implementation provides the fundamental …

Queue Implementation using LinkedList Read More »

Create a Custom LinkedList in Java

Problem Statement: Write a Java program to create a custom LinkedList class with methods to add elements, remove elements, find the length, and reverse the list. Here’s a custom linked list class in Java with methods to add elements, remove elements, find the length, and reverse the list. OUTPUT: Original Linked List:1 -> 2 -> …

Create a Custom LinkedList in Java Read More »

Swap two elements in ArrayList

Problem Statement: Write a Java program to swap the positions of two elements in an ArrayList given their indices. Here’s a Java program that demonstrates how to swap the positions of two elements in an ArrayList given their indices. OUTPUT: Original List: [Apple, Banana, Cherry, Date, Fig]List after swapping elements at index 1 and index …

Swap two elements in ArrayList Read More »

Merge two sorted ArrayLists

Problem Statement: Write a Java program to implement a function to merge two sorted ArrayLists into a single sorted ArrayList. Here’s a Java program that implements a function to merge two sorted ArrayLists into a single sorted ArrayList. OUTPUT: List 1: [2, 5, 8]List 2: [3, 4, 9]Merged List: [2, 3, 4, 5, 8, 9] …

Merge two sorted ArrayLists Read More »