I am currently doing a programming project myself and I require some help.
This is the LinkedList class I am using:
class LinkedList {
Node cursor;
private Node head; // first node in the linked list
private int count;
public int getCount() {
return count;
}
public Node getHead() {
return head;
}
public LinkedList() {
head = null; // creates an empty linked list
count = 0;
}
public void addFront(int n) {
Node newNode = new Node(n);
newNode.setLink(head);
head = newNode;
count++;
}
public void deleteFront() {
if (count > 0) {
Node temp = head;
head = temp.getLink();
temp = null;
count--;
}
}
}
Below are my questions:
How do I create a method to remove a node in the LinkedList at any position? Assuming that the first node has the position of 1, second node has the position of 2 and so on and so forth.
How do I swap the position of nodes for lets say node 1 and node 2?
How do I sort the LinkedList based on the name in ascending order (assuming the name is 'albumName')?