-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.js
More file actions
66 lines (63 loc) · 1.35 KB
/
string.js
File metadata and controls
66 lines (63 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Node{
constructor(data){
this.data=data
this.next=null
}
}
class linkedList{
constructor(){
this.head=null
this.tail=null
}
addnode(data){
let newnode=new Node (data)
if(this.head==null){
this.head=newnode
}
else{
this.tail.next=newnode
}
this.tail=newnode
}
display(){
if(this.head==null){
console.log("empty")
return;
}
let temp=this.head
while(temp!==null){
console.log(temp.data)
temp=temp.next
}
}
insert(next,data){
let newnode=new Node (data)
let current=this.head
while(current!=null&& current.data!=next){
current=current.next
}if(current==null){
return;
}
newnode.next=current.next
current.next=newnode
}
delete(data){
let current=this.head
let prev=null
if(current!=null&¤t.data==data){
this.head=current.next
return;
}
while(current!=null&¤t.data!=data){
prev=current
current=current.next;
}
prev.next=current.next;
}
}
let list =new linkedList()
list.addnode(60)
list.addnode(10)
list.insert(10,68)
list.delete(10)
list.display()