1,107 views

1 Answer

4 votes
4 votes

Answer: B. Ɵ(1), Ɵ(n)

1. Enqueue: create node( O(1) ), make new node point to the first element( O(1) ), make head point to the the new node. O(1)

2. Dequeue: traverse to 2nd last node. O(n) ,make Tail point to this node, O(1), Tail->next = null. O(1)

Once you delete the last node(the node Tail points to) you'll have to set the tail to the last. Since this is a singly linked list, you cannot go back.Therefore you have to traverse the whole list to get to the node which points to last.

Now you can set Tail to t , and Tail->next = NULL

No related questions found