Data Structure Lab 5
Data Structure Lab 5
Node() {
value = 0;
previous = null;
next = null;
}
Node(int val) {
value = val;
previous = null;
next = null;
}
DoublyLinkedList() {
head = null;
tail = null;
}
if (head == null) {
return;
} else {
Node current = head;
d.deleteFromPosition(0);
d.displayBackward();
d.displayForward();
System.out.println("---------------------------------------------------------------
-----------------");
System.out.println("---------------------------------------------------------------
-----------------");
System.out.println("---------------------------------------------------------------
-----------------");
System.out.println("---------------------------------------------------------------
-----------------");
System.out.println("---------------------------------------------------------------
-----------------");
System.out.println("---------------------------------------------------------------
-----------------");
}
}
------------------------------------
EX2:
public Node() {
value = 0;
next = null;
}
public CircularLinkedList() {
head = null;
tail = null;
}
if (head == tail) {
head = null;
tail = null;
} else {
head = head.next;
tail.next = head;
}
}
if (head == tail) {
head = null;
tail = null;
return;
}
Node current = head;
Node prev = null;
prev.next = head;
tail = prev;
}
if (current.value % 2 == 0)
eCLL.insertAtBack(current.value);
current = current.next;
System.out.println("---------------------------------------------------------------
-----------------");
System.out.println("Circular Linked List elements:");
c.display();
System.out.println("---------------------------------------------------------------
-----------------");
System.out.println("---------------------------------------------------------------
-----------------");
System.out.println("---------------------------------------------------------------
-----------------");
----------------------------------------------------------------
EX3:
public Song() {
this.songTitle = null;
this.artistName = null;
}
import java.util.Random;
public Playlist() {
firstNode = null;
lastNode = null;
playlistSize = 0;
}
if (index == 0) {
Node newNode = new Node(newSong);
newNode.setNextNode(firstNode);
firstNode = newNode;
playlistSize++;
return;
}
int i = 0;
while (i < index) {
previous = current;
current = current.getNextNode();
i++;
}
return current.getSong();
}
if (current.getSong().getTitle().equals(title)) {
return current.getSong();
}
return null;
if (current.getSong().getTitle().equals(title)) {
return current.getSong();
}
if (songToRemove == null) {
return;
}
if (current.getSong() == songToRemove) {
if (current == firstNode) {
if (playlistSize == 1) {
firstNode = null;
lastNode = null;
} else {
firstNode = current.getNextNode();
previous.setNextNode(firstNode);
}
} else {
previous.setNextNode(current.getNextNode());
if (current == lastNode) {
lastNode = previous;
}
}
playlistSize--;
}
}
}
public static void main(String[] args) {
Playlist playlist = new Playlist();
System.out.println("Playlist Contents:");
playlist.play();
playlist.clear();
System.out.println("Is the playlist empty after clearing? " +
playlist.isEmpty());
}
}