The Gateway to Computer Science Excellence
0 votes
22 views
Implement a queue by a singly linked list $L$. The operations of $ENQUEUE$ and $DEQUEUE$ should still take $O(1)$ time.
in Algorithms by Boss (41.9k points) | 22 views

1 Answer

0 votes

Maintain two pointers: Head and Tail

DEQUEUE:

temp = new node();

tail->next = temp;

tail = temp;

ENQUEUE:

temp = head;

head = head->next;

delete(temp)

by Active (2k points)
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,647 questions
56,492 answers
195,439 comments
100,703 users