Sorted Singly List
Sorted Singly List
package com.acts;
public Node() {
data = 0;
next = null;
}
Node head;
public SortedLinkedList() {
head = null;
}
@Override
public void insert(int ele) {
Node newNode = new Node(ele); // Create a new node
@Override
public void deleteAll(int ele) {
if (head == null) {
System.out.println("List is empty");
return;
}
@Override
public boolean search(int ele) {
if (head == null) {
System.out.println("List is empty");
return false;
}
@Override
public void print() {
Node current = head;
while (current != null) {
System.out.println(current.data); // Print current node's data
current = current.next; // Move to the next node
}
}
}