44
loading...
This website collects cookies to deliver better user experience
If you are the kind of person who doesn't get even a little spooked when you hear the word "Data-Structure", then you're either a madman or an engineer.
Node(int t){
next=null;
data=t;
}
void insert(int data) {
Node2 t=new Node2(data);
if(head==null) {
head=t;
}
else {
t.next=head;
head=t;
}
}
If it wasn't already apparent from the illustration, not to worry. It's either my awful drawing skills or we just relate better to practical examples.
Node inbtw(int data) {
Node t=new Node(data);
if(head==null) {
head=t;
}
else if(head.next==null) {
head.next=t;
}
else {
t.next=head.next;
head.next=t;
}
return head;
}
void delete() {
if(head==null) {
System.out.println("The list is empty");
return;
}
if(head.next==null) {
System.out.println("The list doesn't have a second element");
return;
}
if(head.next.next==null) {
head.next=null;
return;
}
head.next=head.next.next;
}
Node display(Node s) {
if(s==null||s.next==null) {
System.out.println(s.data);
return head;
}
Node e=display(s.next);
s.next.next=e;
s.next=null;
System.out.println(s.data);
return e;
}