Linked list
Create node
 class Nodetype {
 constructor(f,t) {
 this.f = f;
 this.t=t;
 this.next = null;
 }
 }

Constructor
 let p=new Node(10);
 console.log(p);
 class Linked_List {
 constructor() {
 this.head = null;
 this.size = 0;
 }
null
New_node
This.head=new_node
head
A1
New_head
D1 E1
head1 Head1.next=new_n
ode
p=new Node(f,t)
p.next=i.next
i.next=p
L1.insert_after(C1)
AB
if ((i.next).f==x){
p=new Node(f,t)
p.next=i.next
i.next=p
}//if
B1
Insert new head
 insertHead(f,t) {
 if (this.head==null){
 this.head = new Node(f,t);
 } else{
 let new_head=new Nodetype(f,t);
 new_head.next=this.head;
 this.head=new_head;
 }
 }
Insert a node to end
 insertEnd(f,t){
 let new_node=new Nodetype(f,t);
 let head1=this.head;
 while(head1.next!==null){
 head1=head1.next
 }
 head1.next=new_node;
 }
 }//insert end

Display()
 display(){
 let head1=this.head;
 while(head1!==null){
 process.stdout.write(head1.f.toString()+","+head1.t.toStri
ng()+"-->")
 head1=head1.next
 }

Creating linked list
 let list1=new Linked_List();
 list1.insertHead("MX2460","10:15");
 list1.insertEnd("KO4231","10:20");
 list1.insertEnd("DU21","10:44");

list1.insertHead("IS1345","5:25");
 list1.display()

Creating instance of class
 let list1=new Linked_List();
 list1.insertHead("MX2460","10:15");
 list1.insertEnd("KO4231","10:20");
 list1.insertEnd("DU21","10:44");
 list1.insertEnd("CA21","10:50");
 list1.insertEnd("IN22","11.00");
 list1.display()
 list1.insertHead("IS1345","5:25");
 list1.display()
Inserting a node after
 insert_after(x,f,t){
 for(let i=this.head;i.next!=null; i=i.next){
 if (i.f==x){
 p=new Node(f,t)
 p.next=i.next
 i.next=p
 }//if
 }//for
 console.log("A node added after " +f);
 }//insert_after
Insert_before()
 insert_before(x,f,t){
 for(let i=this.head;i.next!=null; i=i.next){
 if ((i.next).f==x){
 p=new Node(f,t)
 p.next=i.next
 i.next=p
 }//if
 }//for
 console.log("A node added before "+f);
 }//insert_before
A1 B1 C1
A1 B1 C1
Inserting a node at the end
D1
HEAD
Deleting a node
 delete_node(x){
 for (let i=this.head;i.next!=null;i=i.next){
 if ((i.next).f==x){
 i.next=(i.next).next;
 console.log("The node "+x +" is deleted");
 break;
 }
 }
A1 B1 C1
A1
B1
C1
A1 B1 C1
Deleting a node
Arrivals
 The class that manages the two linked lists is called Arrivals.
 Part of the method landed() is shown above. It receives, as a parameter, the flight
number of the flight that has just landed. It then deletes the node representing
this flight from List A and adds it to the end of List B.

(d) Construct the method landed()
Class arrivals
 class Arrivals {
 constructor(listA, listB){
 this.listA = listA;
 this.listB = listB;
 }
 landed(flightLanded) {
 listA.delete_node(flightLanded);
 listB.insertEnd(flightLanded)
 }

Linked list
 let listA=new Linked_List();
 listA.insertHead("MX2460","10:15");
 listA.insertEnd("KO4231","10:20");
 listA.insertEnd("DU21","10:44");
 listA.insertEnd("CA21","10:50");
 listA.insertEnd("IN22","11.00");
 listA.display()
 let listB=new Linked_List();
 listB.insertHead("VT2460","10:15");
 listB.insertEnd("THAI231","10:20");
 listB.insertEnd("CHN21","10:44");
 listB.insertEnd("JA21","10:50");
 listB.insertEnd("JOH22","11.00");
 listB.display();
 //list1.delete_node("DU21");
 //list1.display();
 let Arv=new Arrivals(listA,listB);
 let x=prompt("Enter the flight no which landed?")
 Arv.landed(x);
 listA.display();
 listB.display();
Linked list2

Linked list2

  • 1.
  • 2.
    Create node  classNodetype {  constructor(f,t) {  this.f = f;  this.t=t;  this.next = null;  }  } 
  • 3.
    Constructor  let p=newNode(10);  console.log(p);  class Linked_List {  constructor() {  this.head = null;  this.size = 0;  }
  • 4.
    null New_node This.head=new_node head A1 New_head D1 E1 head1 Head1.next=new_n ode p=newNode(f,t) p.next=i.next i.next=p L1.insert_after(C1) AB if ((i.next).f==x){ p=new Node(f,t) p.next=i.next i.next=p }//if B1
  • 5.
    Insert new head insertHead(f,t) {  if (this.head==null){  this.head = new Node(f,t);  } else{  let new_head=new Nodetype(f,t);  new_head.next=this.head;  this.head=new_head;  }  }
  • 6.
    Insert a nodeto end  insertEnd(f,t){  let new_node=new Nodetype(f,t);  let head1=this.head;  while(head1.next!==null){  head1=head1.next  }  head1.next=new_node;  }  }//insert end 
  • 7.
    Display()  display(){  lethead1=this.head;  while(head1!==null){  process.stdout.write(head1.f.toString()+","+head1.t.toStri ng()+"-->")  head1=head1.next  } 
  • 8.
    Creating linked list let list1=new Linked_List();  list1.insertHead("MX2460","10:15");  list1.insertEnd("KO4231","10:20");  list1.insertEnd("DU21","10:44");  list1.insertHead("IS1345","5:25");  list1.display() 
  • 9.
    Creating instance ofclass  let list1=new Linked_List();  list1.insertHead("MX2460","10:15");  list1.insertEnd("KO4231","10:20");  list1.insertEnd("DU21","10:44");  list1.insertEnd("CA21","10:50");  list1.insertEnd("IN22","11.00");  list1.display()  list1.insertHead("IS1345","5:25");  list1.display()
  • 11.
    Inserting a nodeafter  insert_after(x,f,t){  for(let i=this.head;i.next!=null; i=i.next){  if (i.f==x){  p=new Node(f,t)  p.next=i.next  i.next=p  }//if  }//for  console.log("A node added after " +f);  }//insert_after
  • 13.
    Insert_before()  insert_before(x,f,t){  for(leti=this.head;i.next!=null; i=i.next){  if ((i.next).f==x){  p=new Node(f,t)  p.next=i.next  i.next=p  }//if  }//for  console.log("A node added before "+f);  }//insert_before
  • 14.
    A1 B1 C1 A1B1 C1 Inserting a node at the end D1 HEAD
  • 16.
    Deleting a node delete_node(x){  for (let i=this.head;i.next!=null;i=i.next){  if ((i.next).f==x){  i.next=(i.next).next;  console.log("The node "+x +" is deleted");  break;  }  }
  • 17.
    A1 B1 C1 A1 B1 C1 A1B1 C1 Deleting a node
  • 19.
    Arrivals  The classthat manages the two linked lists is called Arrivals.  Part of the method landed() is shown above. It receives, as a parameter, the flight number of the flight that has just landed. It then deletes the node representing this flight from List A and adds it to the end of List B.  (d) Construct the method landed()
  • 20.
    Class arrivals  classArrivals {  constructor(listA, listB){  this.listA = listA;  this.listB = listB;  }  landed(flightLanded) {  listA.delete_node(flightLanded);  listB.insertEnd(flightLanded)  } 
  • 21.
    Linked list  letlistA=new Linked_List();  listA.insertHead("MX2460","10:15");  listA.insertEnd("KO4231","10:20");  listA.insertEnd("DU21","10:44");  listA.insertEnd("CA21","10:50");  listA.insertEnd("IN22","11.00");  listA.display()
  • 22.
     let listB=newLinked_List();  listB.insertHead("VT2460","10:15");  listB.insertEnd("THAI231","10:20");  listB.insertEnd("CHN21","10:44");  listB.insertEnd("JA21","10:50");  listB.insertEnd("JOH22","11.00");  listB.display();  //list1.delete_node("DU21");  //list1.display();  let Arv=new Arrivals(listA,listB);  let x=prompt("Enter the flight no which landed?")  Arv.landed(x);  listA.display();  listB.display();