@sandeep

if enqueue is pass by reference and dequeue as pass by value
then i think enqueue will be on head....just like stack so it will be O(1)
but for dequeue we need to traverse down the list and remove the last node
O(n)

and if enqueue is made to pass by value and dequeue as pass by reference
do enqueue by traversing down the list and add node at the end O(n)
and for dequeue just move the head pointer to point to next element O(1)

can both of the operations still be done in O(1) ?
i don't find a better way!!


On Tue, Jul 5, 2011 at 10:11 AM, Sandeep Jain <sandeep6...@gmail.com> wrote:

> Its the queue in which you want to add a an element.
> Small correction in the enqueue signature.
>
> void enqueue(NODEPTR &q, int data) // made it a reference, I missed it
>
> And the usage would be something like
> NODEPTR myQueue = NULL;
>
> enqueue(myQueue, 10);
> enqueue(myQueue, 20);
>
> cout<<deque(myQueue);
>
>
>
> Regards,
> Sandeep Jain
>
>
>
>
>
> On Tue, Jul 5, 2011 at 8:30 AM, vaibhav agarwal <
> vibhu.bitspil...@gmail.com> wrote:
>
>> @sandeep what is ptr q in case of enqueue?
>>
>>
>> On Mon, Jul 4, 2011 at 12:53 PM, Sandeep Jain <sandeep6...@gmail.com>wrote:
>>
>>> How bout I say, the insertion and deletion functions have the following
>>> prototype?
>>>
>>>  void enqueue(NODEPTR q, int data)
>>> int deque(NODEPTR q)
>>>
>>> You are not allowed to maintain two pointers, i.e. no front and no rare
>>> pointers...
>>>
>>>
>>> Regards,
>>> Sandeep Jain
>>> Member of Technical Staff, Adobe Systems, India
>>>
>>>
>>>
>>>
>>> On Mon, Jul 4, 2011 at 10:20 PM, surender sanke <surend...@gmail.com>wrote:
>>>
>>>> always maintain front and rear pointers, updating them accordingly
>>>> during insertion and deletion can achieve this in O(1)
>>>>
>>>> surender
>>>>
>>>>
>>>> On Mon, Jul 4, 2011 at 9:59 PM, vaibhav shukla <vaibhav200...@gmail.com
>>>> > wrote:
>>>>
>>>>> How to implement a QUEUE using a singly link list such that the
>>>>> operations ENQUEUE and DEQUEUE takes O(1) time ?
>>>>>
>>>>> --
>>>>>   best wishes!!
>>>>> Vaibhav Shukla
>>>>>
>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to