wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

single linked list

Total questions: 2

Worksheet time: 4mins

Name
Class
Date
1.

What is the functionality of the following code?public void function(Node node)

{

if(size == 0)

head = node;

else

{

Node temp,cur;

for(cur = head; (temp = cur.getNext())!=null; cur = temp);

cur.setNext(node);

}

size++;

}

a)

Inserting a node at the beginning of the list

b)

Deleting a node at the beginning of the list

c)

Inserting a node at the end of the list

d)

Deleting a node at the end of the list

2.

What is the functionality of the following piece of code?public int function(int data)

{

Node temp = head;

int var = 0;

while(temp != null)

{

if(temp.getData() == data)

{

return var;

}

var = var+1;

temp = temp.getNext();

}

return Integer.MIN_VALUE;

}

a)

Find and return the position of the given element in the list

b)

Find and delete a given element in the list

c)

Find and return the given element in the list

d)

Find and insert a new element in the list