algorithm for reversing contents in a queue

Posted on 2006-05-19
Last Modified: 2008-02-26
i want a algorithm for reversing contents in a queue,i want this to be implemented in c
Question by:dinakarsoupaty
    LVL 84

    Accepted Solution

    Is it ok to say
    dequeue each element from queue, push elements onto stack
    pop elements off stack, enqueue elements into queue
    (if you don't have an explicit stack, you can use the function call stack recursively)
    LVL 53

    Expert Comment

    Depending on the queue implementation, this can be done by just reversing the pointers (if the queue is built up from nodes connected with pointers) ... That prevents a lot of memory copies and/or (recursive) function calls. It can be done in O(n) time.

    Can you tell a bit more about your queue implementation ?

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
    This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now