Correct the code:-
public class DLL {
private Node start;
private Node end;
int count;
public DLL() {
start = end = null;
count=0;
}
public void insertAtstrat (Data d) {
if (count == 0) {
Node tn = new Node(d,null,null);
start = end = tn;
}
else {
Node tn = new Node (d,start,null);
start.prev = tn;
start (tn);
count++;
}
}
public void insertAtend (Data d) {
if (count == 0) {
insertAtend(d);
}
else {
Node tn = new Node(d,null,end);
end.next = tn;
end = tn;
count++;
}
public void insertAt(Data d, index i) {
if (count ==0 || index == 0);
insertAtstart(d);
else if (i >= count);
insertAtend(d);
else {
Node temp = start;
for (a = 1);
temp = temp.Node;
Node tn = new Node(d, temp.next, temp);
temp.next = tn;
temp = tn.next;
temp.prev = tn;
}
}
}
}
public class Node {
Data d;
Node next;
Node prev;
public Node (Data d,Node n,Node p) {
d = new Data();
next = n;
prev = p;
}
public class DLL {
private Node start;
private Node end;
private int count;
public DLL() {
start = end = null;
count = 0;
}
public void insertAtStart(Data d) {
Node tn = new Node(d, null, null);
if (count == 0) {
start = end = tn;
} else {
tn.next = start;
start.prev = tn;
start = tn;
}
count++;
}
public void insertAtEnd(Data d) {
if (count == 0) {
insertAtStart(d);
} else {
Node tn = new Node(d, null, end);
end.next = tn;
end = tn;
count++;
}
}
public void insertAt(Data d, int index) {
if (count == 0 || index == 0) {
insertAtStart(d);
} else if (index >= count) {
insertAtEnd(d);
} else {
Node temp = start;
for (int i = 0; i < index; i++, temp = temp.next) ;
Node tn = new Node(d, temp, temp.prev);
temp.prev.next = tn;
temp.prev = tn;
}
}
}
public class Node {
Data d;
Node next;
Node prev;
public Node(Data d, Node n, Node p) {
this.d = d;
next = n;
prev = p;
}
}
Comments
Leave a comment