Linked List
Linked List
Assignment Questions
Assignment Questions
LinkedList
Assignment Questions
1) Given a double LinkedList. There are 2 types of pointers in this. One pointer is the same as a single LinkedList
which will point to the next node while another pointer is pointing to any random node in the linkedlist. You
need to clone this linkedlist.
MCQ Questions
1) Which node will be the top element of the stack when we implement the stack using LinkedList?
A) First node
B) Last node
C) Second node
D) None
D) None
A) True
B) false
A) Deleting
B) Traversing
C) Inserting
D) None
D) None
6
Assignment Questions
5) When we delete an element from the index which is not present in the array, which condition is that?
A) Overflow
B) Underflow
C) Garbage
D) None
6
LinkedList
Assignment Solutions
Assignment Solutions
LinkedList
Assignment Solutions
class Node {
constructor(x) {
this.data = x;
function print(start) {
document.write(
"Node = " +
+ ptr.random.data+"<br/>"
);
ptr = ptr.next;
function clone(start) {
temp = curr.next;
curr.next.next = temp;
curr = temp;
curr = start;
if (curr.next != null)
curr.random.next : curr.random;
curr.next.next : curr.next;
}
6
Assignment Solutions
temp = copy;
original.next.next : original.next;
copy.next.next : copy.next;
original = original.next;
copy = copy.next;
return temp;
start.random = start.next.next;
start.next.random = start;
start.next.next.random =
start.next.next.next.next;
start.next.next.next.random =
start.next.next.next.next;
start.next.next.next.next.random =
start.next;
print(start);
print(cloned_list);
6
Assignment Solutions
class Node
constructor(d)
this.data = d;
function splitList()
if (head == null) {
return;
fast_ptr = fast_ptr.next.next;
slow_ptr = slow_ptr.next;
if (fast_ptr.next.next == head) {
fast_ptr = fast_ptr.next;
head1 = head;
if (head.next != head) {
head2 = slow_ptr.next;
fast_ptr.next = slow_ptr.next;
slow_ptr.next = head;
6
}
Assignment Solutions
function printList(node) {
if (node != null) {
do {
temp = temp.next;
head.next.next.next.next = head;
printList(head);
splitList();
document.write("<br>");
printList(head1);
document.write("<br>");
printList(head2);
MCQ Answers
A
B
A
A
B