a) the following code gives ther partially completed implementation of a Singly Linked List. In this implementation, write the addToHead() method. Note that the instance variables of the Node class are defined as public so you can manipulate them directly.

public class node {
public Object data;
public Node next;
}

public class SinglyLinkedList {
private Node head;
private int size;

public SinglyLinkedList() {
head = null;
size = 0;
}

public void addToHead(Object o){
//complete this method






b)Write the addToTail()method for the SinglyLinkedList class.

public void addToTail(Object o){
//complete this method



c)What is the big-O running time of the addToHead() method?



d)What is the big-O running time of the addToTail() method?





My answer are:
addToHead:
Node node=new Node();
node.data=o;
if(size==0)
head=node;
else{
Node temp=head;
head=node;
node.next=temp;
}


addToTail:
Node node=new Node();
node.data=o;
if(size==0)
head=node;
else{
Node temp=head;
while(temp.next!=null)
temp=temp.next;
temp.next=node;
}


O(1)


O(n)

are those right? thank you