Linked Lists
- Write a Java program to create and display a singly linked list.
- Expected Output:
Linked List: 1 -> 2 -> 3 -> null
- Write a Java program to insert an element at the beginning of a singly linked list.
- Input: Insert
5
- Expected Output:
Linked List after inserting 5: 5 -> 1 -> 2 -> 3 -> null
- Input: Insert
- Write a Java program to insert an element at the end of a singly linked list.
- Input: Insert
4
- Expected Output:
Linked List after inserting 4: 1 -> 2 -> 3 -> 4 -> null
- Input: Insert
- Write a Java program to delete an element from a singly linked list by key.
- Input: Delete
2
- Expected Output:
Linked List after deleting 2: 1 -> 3 -> 4 -> null
- Input: Delete
- Write a Java program to find the length of a singly linked list.
- Expected Output:
Length of Linked List: 4
- Expected Output:
Stacks
- Write a Java program to implement a stack using an array. Include operations for push, pop, and display.
- Input: Push
5, 10, 15
- Expected Output:
Stack: [5, 10, 15]
- Input: Push
- Write a Java program to implement a stack using linked list. Include operations for push, pop, and display.
- Input: Push
5, 10, 15
- Expected Output:
Stack: 15 -> 10 -> 5
- Input: Push
- Write a Java program to reverse a string using a stack.
- Input:
Hello
- Expected Output:
Reversed String: olleH
- Input:
Queues
- Write a Java program to implement a queue using an array. Include operations for enqueue, dequeue, and display.
- Input: Enqueue
5, 10, 15
- Expected Output:
Queue: [5, 10, 15]
- Input: Enqueue
- Write a Java program to implement a queue using linked list. Include operations for enqueue, dequeue, and display.
- Input: Enqueue
5, 10, 15
- Expected Output:
Queue: 5 -> 10 -> 15
- Input: Enqueue
- Write a Java program to reverse the first K elements of a queue.
- Input: Queue
1, 2, 3, 4, 5
and K3
- Expected Output:
Queue after reversing first 3 elements: 3 -> 2 -> 1 -> 4 -> 5
- Input: Queue
Trees
- Write a Java program to implement a binary search tree (BST). Include operations for insertion, deletion, and traversal (inorder, preorder, and postorder).
- Input: Insert
5, 3, 7, 2, 4, 6
- Expected Output: (Inorder traversal)
BST: 2 -> 3 -> 4 -> 5 -> 6 -> 7
- Input: Insert
- Write a Java program to find the height of a binary tree.
- Input: BST
5, 3, 7, 2, 4, 6
- Expected Output:
Height of BST: 3
- Input: BST
- Write a Java program to count leaf nodes in a binary tree.
- Input: BST
5, 3, 7, 2, 4, 6
- Expected Output:
Leaf nodes in BST: 3
- Input: BST
Latest posts by Mahesh Wabale (see all)
- AnchorSetup using Docker-Compose - October 18, 2024
- Devops assignment - October 17, 2024
- Deployment of vault HA using MySQL - September 18, 2024