-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreverese str.html
119 lines (101 loc) · 2.47 KB
/
reverese str.html
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang="en">
<title></title>
<head>
<script>
class Node {
constructor(data, next = null) {
this.data = data;
this.next = next;
}
}
class LinkedList {
constructor() {
this.head = null;
}
getLast(){
if(!this.head){
return null;
}
let node=this.head;
while(node){
if(!node.next){
return node;
}
node=node.next;
}
}
insertLast(data){
let lastNode= this.getLast();
if(lastNode){
lastNode.next=new Node(data);
}else{
this.head=new Node(data);
}
}
fecthNode(){
let node=this.head;
let arr1=[];
while(node){
arr1.push(node);
node=node.next;
}
return arr1;
}
clear(){
this.head=null;
}
partition(x){
let node=this.fecthNode();
let i=0;
let arrless3=[];
let arreq3=[];
let arrgrt3=[];
let finalArr=[];
while(i<node.length){
// console.log(node[i].data+"ok");
let tempData=node[i].data;
if(tempData<x){
arrless3.push(tempData);
}else if(tempData==x){
arreq3.push(tempData);
}else if(tempData>x){
arrgrt3.push(tempData);
}
i++;
}
arrless3.sort(function(a,b){return a-b;});
arrgrt3.sort(function(a,b){return a-b;});
finalArr.push(...arrless3);
finalArr.push(...arreq3);
finalArr.push(...arrgrt3);
this.clear();
for(let val of finalArr){
this.insertLast(val);
}
return finalArr;
}
}
let l = new LinkedList();
//input nodes//
l.insertLast(1);
l.insertLast(4);
l.insertLast(2);
l.insertLast(3);
l.insertLast(5);
//input....
console.log(l);
console.log(l.getLast());
//partition node as required value of x , i have gave x=3
console.log(l.partition(3));
//output
console.log(l);
</script>
</head>
<body>
<div style="position:absolute; width:600px;height:500px;border:solid 1px green;top:10px;left:30px;">
<div style="position:absolute;width:50px;height:50px;border:solid 1px red;top:20px;left:10px;"></div>
<div style="position:absolute;width:50px;height:50px;border:solid 1px red;top:20px;left:10px;"></div>
</div>
</body>
</html>