Hi Customer,
We understand that your query seems general without any
Syncfusion components. To achieve your requirements without any issue, follow
this requirement.
- Create
Node class to represent linked list.
class Node {
int
value;
Node
next;
public
Node(int value) {
this.value = value;
this.next = null;
}
}
|
- Create
the linked list class that process the node.
class LinkedList {
Node head;
public void reverse() {
Node previous = null;
Node current = head;
Node next = null;
while (current != null) {
next = current.next;
current.next = previous;
previous = current;
current = next;
}
head = previous;
}
public void insert(int value) {
Node newNode = new Node(value);
if (head == null) {
head = newNode;
} else {
Node current = head;
while (current.next != null) {
current = current.next;
}
current.next = newNode;
}
}
public void display() {
Node current = head;
while (current != null) {
System.out.print(current.value +
" ");
current = current.next;
}
System.out.println();
}
}
|
- Now,
populate the list and reverse it.
public class Main {
public static
void main(String[] args) {
LinkedList
linkedList = new LinkedList();
linkedList.insert(1);
linkedList.insert(2);
linkedList.insert(3);
linkedList.insert(4);
linkedList.insert(5);
System.out.println("Original list:");
linkedList.display();
System.out.println("Reversed list:");
linkedList.reverse();
linkedList.display();
}
}
|
We ensured that the above code would work properly while execute
it. Could you please share any requirements while integrating our Syncfusion
components?
Regards,
Rajendran R.