<script>
class Node
{
constructor()
{
let data,next;
}
}
function
reverse(head_ref,size)
{
let current = head_ref;
let TEMP_ARR =
new
Array(size);
let i = 0;
while
(current !=
null
)
{
if
((current.data.charCodeAt(0) >= 97 &&
current.data.charCodeAt(0) <= 122) ||
(current.data.charCodeAt(0) >= 65 &&
current.data.charCodeAt(0) <= 90))
{
TEMP_ARR[i++] = current.data;
current = current.next;
}
else
current = current.next;
}
current = head_ref;
while
(current !=
null
)
{
if
((current.data.charCodeAt(0) >= 97 &&
current.data.charCodeAt(0) <= 122) ||
(current.data.charCodeAt(0) >= 65 &&
current.data.charCodeAt(0) <= 90))
{
current.data = TEMP_ARR[--i];
current = current.next;
}
else
current = current.next;
}
return
head_ref;
}
function
push(head_ref,new_data)
{
let new_node =
new
Node();
new_node.data = new_data;
new_node.next = (head_ref);
(head_ref) = new_node;
return
head_ref;
}
function
printList(head)
{
let temp = head;
while
(temp !=
null
)
{
document.write(temp.data);
temp = temp.next;
}
}
let head =
null
;
head = push(head,
's'
);
head = push(head,
'$'
);
head = push(head,
'k'
);
head = push(head,
'e'
);
head = push(head,
'e'
);
head = push(head,
'@'
);
head = push(head,
'#'
);
head = push(head,
'g'
);
head = push(head,
'r'
);
head = push(head,
'o'
);
head = push(head,
'f'
);
head = push(head,
's'
);
head = push(head,
'$'
);
head = push(head,
'k'
);
head = push(head,
'e'
);
head = push(head,
'e'
);
head = push(head,
'g'
);
document.write(
"Given linked list: "
);
printList(head);
head=reverse(head, 13);
document.write(
"<br>Reversed Linked list: "
);
printList(head);
</script>